Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/tests/ export-ignore
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"autoload": {
"files": [ "src/functions_include.php" ]
},
"autoload-dev": {
"psr-4": { "Clue\\Tests\\React\\Block\\": "tests/" }
},
"require": {
"php": ">=5.3",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
Expand Down
9 changes: 2 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Block React Test Suite">
<directory>./tests/</directory>
Expand All @@ -16,4 +11,4 @@
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
18 changes: 10 additions & 8 deletions tests/FunctionAwaitAllTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

use Clue\React\Block;
namespace Clue\Tests\React\Block;

use React\Promise;
use React\Promise\Timer\TimeoutException;
use Clue\React\Block;

class FunctionAwaitAllTest extends TestCase
{
Expand All @@ -29,7 +31,7 @@ public function testAwaitAllRejected()
{
$all = array(
$this->createPromiseResolved(1),
$this->createPromiseRejected(new Exception('test'))
$this->createPromiseRejected(new \Exception('test'))
);

Block\awaitAll($all, $this->loop);
Expand All @@ -55,8 +57,8 @@ public function testAwaitAllRejectedWithFalseWillWrapInUnexpectedValueException(
public function testAwaitAllOnlyRejected()
{
$all = array(
$this->createPromiseRejected(new Exception('first')),
$this->createPromiseRejected(new Exception('second'))
$this->createPromiseRejected(new \Exception('first')),
$this->createPromiseRejected(new \Exception('second'))
);

Block\awaitAll($all, $this->loop);
Expand All @@ -78,14 +80,14 @@ public function testAwaitAllWithRejectedWillCancelPending()
});

$all = array(
Promise\reject(new Exception('test')),
Promise\reject(new \Exception('test')),
$promise
);

try {
Block\awaitAll($all, $this->loop);
$this->fail();
} catch (Exception $expected) {
} catch (\Exception $expected) {
$this->assertEquals('test', $expected->getMessage());
$this->assertTrue($cancelled);
}
Expand Down Expand Up @@ -117,11 +119,11 @@ public function testAwaitAllPendingPromiseWithTimeoutAndCancellerShouldNotCreate
gc_collect_cycles();

$promise = new \React\Promise\Promise(function () { }, function () {
throw new RuntimeException();
throw new \RuntimeException();
});
try {
Block\awaitAll(array($promise), $this->loop, 0.001);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand Down
8 changes: 5 additions & 3 deletions tests/FunctionAwaitAnyTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

use Clue\React\Block;
namespace Clue\Tests\React\Block;

use React\Promise\Deferred;
use React\Promise;
use React\Promise\Timer\TimeoutException;
use Clue\React\Block;

class FunctionAwaitAnyTest extends TestCase
{
Expand Down Expand Up @@ -110,11 +112,11 @@ public function testAwaitAnyPendingPromiseWithTimeoutAndCancellerShouldNotCreate
gc_collect_cycles();

$promise = new \React\Promise\Promise(function () { }, function () {
throw new RuntimeException();
throw new \RuntimeException();
});
try {
Block\awaitAny(array($promise), $this->loop, 0.001);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand Down
28 changes: 15 additions & 13 deletions tests/FunctionAwaitTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

use Clue\React\Block;
namespace Clue\Tests\React\Block;

use React\Promise;
use React\Promise\Timer\TimeoutException;
use Clue\React\Block;

class FunctionAwaitTest extends TestCase
{
Expand All @@ -12,7 +14,7 @@ class FunctionAwaitTest extends TestCase
*/
public function testAwaitOneRejected()
{
$promise = $this->createPromiseRejected(new Exception('test'));
$promise = $this->createPromiseRejected(new \Exception('test'));

Block\await($promise, $this->loop);
}
Expand Down Expand Up @@ -44,12 +46,12 @@ public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException()
*/
public function testAwaitOneRejectedWithPhp7ErrorWillWrapInUnexpectedValueExceptionWithPrevious()
{
$promise = Promise\reject(new Error('Test'));
$promise = Promise\reject(new \Error('Test'));

try {
Block\await($promise, $this->loop);
$this->fail();
} catch (UnexpectedValueException $e) {
} catch (\UnexpectedValueException $e) {
$this->assertEquals('Promise rejected with unexpected value of type Error', $e->getMessage());
$this->assertInstanceOf('Throwable', $e->getPrevious());
$this->assertEquals('Test', $e->getPrevious()->getMessage());
Expand Down Expand Up @@ -130,10 +132,10 @@ public function testAwaitOneRejectedShouldNotCreateAnyGarbageReferences()

gc_collect_cycles();

$promise = Promise\reject(new RuntimeException());
$promise = Promise\reject(new \RuntimeException());
try {
Block\await($promise, $this->loop);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand All @@ -149,10 +151,10 @@ public function testAwaitOneRejectedWithTimeoutShouldNotCreateAnyGarbageReferenc

gc_collect_cycles();

$promise = Promise\reject(new RuntimeException());
$promise = Promise\reject(new \RuntimeException());
try {
Block\await($promise, $this->loop, 0.001);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand All @@ -171,7 +173,7 @@ public function testAwaitNullValueShouldNotCreateAnyGarbageReferences()
$promise = Promise\reject(null);
try {
Block\await($promise, $this->loop);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand All @@ -191,11 +193,11 @@ public function testAwaitPendingPromiseWithTimeoutAndCancellerShouldNotCreateAny
gc_collect_cycles();

$promise = new \React\Promise\Promise(function () { }, function () {
throw new RuntimeException();
throw new \RuntimeException();
});
try {
Block\await($promise, $this->loop, 0.001);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand All @@ -213,7 +215,7 @@ public function testAwaitPendingPromiseWithTimeoutAndWithoutCancellerShouldNotCr
$promise = new \React\Promise\Promise(function () { });
try {
Block\await($promise, $this->loop, 0.001);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand All @@ -233,7 +235,7 @@ public function testAwaitPendingPromiseWithTimeoutAndNoOpCancellerShouldNotCreat
});
try {
Block\await($promise, $this->loop, 0.001);
} catch (Exception $e) {
} catch (\Exception $e) {
// no-op
}
unset($promise, $e);
Expand Down
2 changes: 2 additions & 0 deletions tests/FunctionSleepTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\Tests\React\Block;

use Clue\React\Block;

class FunctionSleepTest extends TestCase
Expand Down
8 changes: 3 additions & 5 deletions tests/bootstrap.php → tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php

namespace Clue\Tests\React\Block;

use PHPUnit\Framework\TestCase as BaseTestCase;
use React\Promise\Deferred;

require_once __DIR__ . '/../vendor/autoload.php';

error_reporting(-1);

class TestCase extends BaseTestCase
{
protected $loop;

public function setUp()
{
$this->loop = React\EventLoop\Factory::create();
$this->loop = \React\EventLoop\Factory::create();
}

protected function createPromiseResolved($value = null, $delay = 0.01)
Expand Down