Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize test suite #148

Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "~6.4"
"phpunit/phpunit": "^7"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand Down
8 changes: 5 additions & 3 deletions tests/FulfilledPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Promise;

use InvalidArgumentException;
WyriHaximus marked this conversation as resolved.
Show resolved Hide resolved
use LogicException;
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;

class FulfilledPromiseTest extends TestCase
Expand All @@ -16,7 +18,7 @@ public function getPromiseTestAdapter(callable $canceller = null)
return new CallbackPromiseAdapter([
'promise' => function () use (&$promise) {
if (!$promise) {
throw new \LogicException('FulfilledPromise must be resolved before obtaining the promise');
throw new LogicException('FulfilledPromise must be resolved before obtaining the promise');
}

return $promise;
Expand All @@ -27,7 +29,7 @@ public function getPromiseTestAdapter(callable $canceller = null)
}
},
'reject' => function () {
throw new \LogicException('You cannot call reject() for React\Promise\FulfilledPromise');
throw new LogicException('You cannot call reject() for React\Promise\FulfilledPromise');
},
'settle' => function ($value = null) use (&$promise) {
if (!$promise) {
Expand All @@ -39,10 +41,10 @@ public function getPromiseTestAdapter(callable $canceller = null)

/**
* @test
* @expectedException InvalidArgumentException
*/
public function shouldThrowExceptionIfConstructedWithAPromise()
{
$this->expectException(InvalidArgumentException::class);
return new FulfilledPromise(new FulfilledPromise());
}
}
30 changes: 16 additions & 14 deletions tests/FunctionAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace React\Promise;

use Exception;

class FunctionAllTest extends TestCase
{
/** @test */
public function shouldResolveEmptyInput()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo([]));
->with(self::identicalTo([]));

all([])
->then($mock);
Expand All @@ -22,9 +24,9 @@ public function shouldResolveValuesArray()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo([1, 2, 3]));
->with(self::identicalTo([1, 2, 3]));

all([1, 2, 3])
->then($mock);
Expand All @@ -35,9 +37,9 @@ public function shouldResolvePromisesArray()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo([1, 2, 3]));
->with(self::identicalTo([1, 2, 3]));

all([resolve(1), resolve(2), resolve(3)])
->then($mock);
Expand All @@ -48,9 +50,9 @@ public function shouldResolveSparseArrayInput()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo([null, 1, null, 1, 1]));
->with(self::identicalTo([null, 1, null, 1, 1]));

all([null, 1, null, 1, 1])
->then($mock);
Expand All @@ -59,14 +61,14 @@ public function shouldResolveSparseArrayInput()
/** @test */
public function shouldRejectIfAnyInputPromiseRejects()
{
$exception2 = new \Exception();
$exception3 = new \Exception();
$exception2 = new Exception();
$exception3 = new Exception();

$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo($exception2));
->with(self::identicalTo($exception2));

all([resolve(1), reject($exception2), resolve($exception3)])
->then($this->expectCallableNever(), $mock);
Expand All @@ -77,9 +79,9 @@ public function shouldPreserveTheOrderOfArrayWhenResolvingAsyncPromises()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo([1, 2, 3]));
->with(self::identicalTo([1, 2, 3]));

$deferred = new Deferred();

Expand Down
33 changes: 17 additions & 16 deletions tests/FunctionAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace React\Promise;

use Exception;
use React\Promise\Exception\CompositeException;
use React\Promise\Exception\LengthException;

Expand All @@ -12,10 +13,10 @@ public function shouldRejectWithLengthExceptionWithEmptyInputArray()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with(
$this->callback(function ($exception) {
self::callback(function ($exception) {
return $exception instanceof LengthException &&
'Input array must contain at least 1 item but contains only 0 items.' === $exception->getMessage();
})
Expand All @@ -30,9 +31,9 @@ public function shouldResolveWithAnInputValue()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo(1));
->with(self::identicalTo(1));

any([1, 2, 3])
->then($mock);
Expand All @@ -43,9 +44,9 @@ public function shouldResolveWithAPromisedInputValue()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo(1));
->with(self::identicalTo(1));

any([resolve(1), resolve(2), resolve(3)])
->then($mock);
Expand All @@ -54,9 +55,9 @@ public function shouldResolveWithAPromisedInputValue()
/** @test */
public function shouldRejectWithAllRejectedInputValuesIfAllInputsAreRejected()
{
$exception1 = new \Exception();
$exception2 = new \Exception();
$exception3 = new \Exception();
$exception1 = new Exception();
$exception2 = new Exception();
$exception3 = new Exception();

$compositeException = new CompositeException(
[0 => $exception1, 1 => $exception2, 2 => $exception3],
Expand All @@ -65,7 +66,7 @@ public function shouldRejectWithAllRejectedInputValuesIfAllInputsAreRejected()

$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($compositeException);

Expand All @@ -76,14 +77,14 @@ public function shouldRejectWithAllRejectedInputValuesIfAllInputsAreRejected()
/** @test */
public function shouldResolveWhenFirstInputPromiseResolves()
{
$exception2 = new \Exception();
$exception3 = new \Exception();
$exception2 = new Exception();
$exception3 = new Exception();

$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo(1));
->with(self::identicalTo(1));

any([resolve(1), reject($exception2), reject($exception3)])
->then($mock);
Expand All @@ -94,9 +95,9 @@ public function shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->expects(self::once())
->method('__invoke')
->with($this->identicalTo(2));
->with(self::identicalTo(2));

$d1 = new Deferred();
$d2 = new Deferred();
Expand Down
43 changes: 23 additions & 20 deletions tests/FunctionCheckTypehintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,79 @@

namespace React\Promise;

use Exception;
use InvalidArgumentException;

class FunctionCheckTypehintTest extends TestCase
{
/** @test */
public function shouldAcceptClosureCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) {}, new \InvalidArgumentException()));
$this->assertFalse(_checkTypehint(function (\InvalidArgumentException $e) {}, new \Exception()));
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {}, new InvalidArgumentException()));
self::assertFalse(_checkTypehint(function (InvalidArgumentException $e) {}, new Exception()));
}

/** @test */
public function shouldAcceptFunctionStringCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint('React\Promise\testCallbackWithTypehint', new \InvalidArgumentException()));
$this->assertFalse(_checkTypehint('React\Promise\testCallbackWithTypehint', new \Exception()));
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
self::assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new Exception()));
}

/** @test */
public function shouldAcceptInvokableObjectCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new \InvalidArgumentException()));
$this->assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception()));
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
self::assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new Exception()));
}

/** @test */
public function shouldAcceptObjectMethodCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
$this->assertFalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception()));
self::assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new Exception()));
}

/** @test */
public function shouldAcceptStaticClassCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
$this->assertFalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception()));
self::assertTrue(_checkTypehint([TestCallbackWithTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([TestCallbackWithTypehintClass::class, 'testCallbackStatic'], new Exception()));
}

/** @test */
public function shouldAcceptClosureCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) {
}, new \InvalidArgumentException()));
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {
}, new InvalidArgumentException()));
}

/** @test */
public function shouldAcceptFunctionStringCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint('React\Promise\testCallbackWithoutTypehint', new \InvalidArgumentException()));
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
}

/** @test */
public function shouldAcceptInvokableObjectCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new \InvalidArgumentException()));
self::assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new InvalidArgumentException()));
}

/** @test */
public function shouldAcceptObjectMethodCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
self::assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new InvalidArgumentException()));
}

/** @test */
public function shouldAcceptStaticClassCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithoutTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
self::assertTrue(_checkTypehint([TestCallbackWithoutTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
}
}

function testCallbackWithTypehint(\InvalidArgumentException $e)
function testCallbackWithTypehint(InvalidArgumentException $e)
{
}

Expand All @@ -81,15 +84,15 @@ function testCallbackWithoutTypehint()

class TestCallbackWithTypehintClass
{
public function __invoke(\InvalidArgumentException $e)
public function __invoke(InvalidArgumentException $e)
{
}

public function testCallback(\InvalidArgumentException $e)
public function testCallback(InvalidArgumentException $e)
{
}

public static function testCallbackStatic(\InvalidArgumentException $e)
public static function testCallbackStatic(InvalidArgumentException $e)
{
}
}
Expand Down
Loading