Skip to content

Commit 15036d2

Browse files
authored
Merge pull request #148 from WyriHaximus-secret-labs/rector-phpunit-upgrades
Modernize test suite
2 parents d0f2f2a + b41ca0f commit 15036d2

26 files changed

+395
-340
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"php": ">=7.1.0"
1010
},
1111
"require-dev": {
12-
"phpunit/phpunit": "~6.4"
12+
"phpunit/phpunit": "^7"
1313
},
1414
"autoload": {
1515
"psr-4": {

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="vendor/autoload.php"
1312
>
1413
<testsuites>

tests/FulfilledPromiseTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace React\Promise;
44

5+
use InvalidArgumentException;
6+
use LogicException;
57
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
68

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

2224
return $promise;
@@ -27,7 +29,7 @@ public function getPromiseTestAdapter(callable $canceller = null)
2729
}
2830
},
2931
'reject' => function () {
30-
throw new \LogicException('You cannot call reject() for React\Promise\FulfilledPromise');
32+
throw new LogicException('You cannot call reject() for React\Promise\FulfilledPromise');
3133
},
3234
'settle' => function ($value = null) use (&$promise) {
3335
if (!$promise) {
@@ -39,10 +41,10 @@ public function getPromiseTestAdapter(callable $canceller = null)
3941

4042
/**
4143
* @test
42-
* @expectedException InvalidArgumentException
4344
*/
4445
public function shouldThrowExceptionIfConstructedWithAPromise()
4546
{
47+
$this->expectException(InvalidArgumentException::class);
4648
return new FulfilledPromise(new FulfilledPromise());
4749
}
4850
}

tests/FunctionAllTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
namespace React\Promise;
44

5+
use Exception;
6+
57
class FunctionAllTest extends TestCase
68
{
79
/** @test */
810
public function shouldResolveEmptyInput()
911
{
1012
$mock = $this->createCallableMock();
1113
$mock
12-
->expects($this->once())
14+
->expects(self::once())
1315
->method('__invoke')
14-
->with($this->identicalTo([]));
16+
->with(self::identicalTo([]));
1517

1618
all([])
1719
->then($mock);
@@ -22,9 +24,9 @@ public function shouldResolveValuesArray()
2224
{
2325
$mock = $this->createCallableMock();
2426
$mock
25-
->expects($this->once())
27+
->expects(self::once())
2628
->method('__invoke')
27-
->with($this->identicalTo([1, 2, 3]));
29+
->with(self::identicalTo([1, 2, 3]));
2830

2931
all([1, 2, 3])
3032
->then($mock);
@@ -35,9 +37,9 @@ public function shouldResolvePromisesArray()
3537
{
3638
$mock = $this->createCallableMock();
3739
$mock
38-
->expects($this->once())
40+
->expects(self::once())
3941
->method('__invoke')
40-
->with($this->identicalTo([1, 2, 3]));
42+
->with(self::identicalTo([1, 2, 3]));
4143

4244
all([resolve(1), resolve(2), resolve(3)])
4345
->then($mock);
@@ -48,9 +50,9 @@ public function shouldResolveSparseArrayInput()
4850
{
4951
$mock = $this->createCallableMock();
5052
$mock
51-
->expects($this->once())
53+
->expects(self::once())
5254
->method('__invoke')
53-
->with($this->identicalTo([null, 1, null, 1, 1]));
55+
->with(self::identicalTo([null, 1, null, 1, 1]));
5456

5557
all([null, 1, null, 1, 1])
5658
->then($mock);
@@ -59,14 +61,14 @@ public function shouldResolveSparseArrayInput()
5961
/** @test */
6062
public function shouldRejectIfAnyInputPromiseRejects()
6163
{
62-
$exception2 = new \Exception();
63-
$exception3 = new \Exception();
64+
$exception2 = new Exception();
65+
$exception3 = new Exception();
6466

6567
$mock = $this->createCallableMock();
6668
$mock
67-
->expects($this->once())
69+
->expects(self::once())
6870
->method('__invoke')
69-
->with($this->identicalTo($exception2));
71+
->with(self::identicalTo($exception2));
7072

7173
all([resolve(1), reject($exception2), resolve($exception3)])
7274
->then($this->expectCallableNever(), $mock);
@@ -77,9 +79,9 @@ public function shouldPreserveTheOrderOfArrayWhenResolvingAsyncPromises()
7779
{
7880
$mock = $this->createCallableMock();
7981
$mock
80-
->expects($this->once())
82+
->expects(self::once())
8183
->method('__invoke')
82-
->with($this->identicalTo([1, 2, 3]));
84+
->with(self::identicalTo([1, 2, 3]));
8385

8486
$deferred = new Deferred();
8587

tests/FunctionAnyTest.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace React\Promise;
44

5+
use Exception;
56
use React\Promise\Exception\CompositeException;
67
use React\Promise\Exception\LengthException;
78

@@ -12,10 +13,10 @@ public function shouldRejectWithLengthExceptionWithEmptyInputArray()
1213
{
1314
$mock = $this->createCallableMock();
1415
$mock
15-
->expects($this->once())
16+
->expects(self::once())
1617
->method('__invoke')
1718
->with(
18-
$this->callback(function ($exception) {
19+
self::callback(function ($exception) {
1920
return $exception instanceof LengthException &&
2021
'Input array must contain at least 1 item but contains only 0 items.' === $exception->getMessage();
2122
})
@@ -30,9 +31,9 @@ public function shouldResolveWithAnInputValue()
3031
{
3132
$mock = $this->createCallableMock();
3233
$mock
33-
->expects($this->once())
34+
->expects(self::once())
3435
->method('__invoke')
35-
->with($this->identicalTo(1));
36+
->with(self::identicalTo(1));
3637

3738
any([1, 2, 3])
3839
->then($mock);
@@ -43,9 +44,9 @@ public function shouldResolveWithAPromisedInputValue()
4344
{
4445
$mock = $this->createCallableMock();
4546
$mock
46-
->expects($this->once())
47+
->expects(self::once())
4748
->method('__invoke')
48-
->with($this->identicalTo(1));
49+
->with(self::identicalTo(1));
4950

5051
any([resolve(1), resolve(2), resolve(3)])
5152
->then($mock);
@@ -54,9 +55,9 @@ public function shouldResolveWithAPromisedInputValue()
5455
/** @test */
5556
public function shouldRejectWithAllRejectedInputValuesIfAllInputsAreRejected()
5657
{
57-
$exception1 = new \Exception();
58-
$exception2 = new \Exception();
59-
$exception3 = new \Exception();
58+
$exception1 = new Exception();
59+
$exception2 = new Exception();
60+
$exception3 = new Exception();
6061

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

6667
$mock = $this->createCallableMock();
6768
$mock
68-
->expects($this->once())
69+
->expects(self::once())
6970
->method('__invoke')
7071
->with($compositeException);
7172

@@ -76,14 +77,14 @@ public function shouldRejectWithAllRejectedInputValuesIfAllInputsAreRejected()
7677
/** @test */
7778
public function shouldResolveWhenFirstInputPromiseResolves()
7879
{
79-
$exception2 = new \Exception();
80-
$exception3 = new \Exception();
80+
$exception2 = new Exception();
81+
$exception3 = new Exception();
8182

8283
$mock = $this->createCallableMock();
8384
$mock
84-
->expects($this->once())
85+
->expects(self::once())
8586
->method('__invoke')
86-
->with($this->identicalTo(1));
87+
->with(self::identicalTo(1));
8788

8889
any([resolve(1), reject($exception2), reject($exception3)])
8990
->then($mock);
@@ -94,9 +95,9 @@ public function shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue
9495
{
9596
$mock = $this->createCallableMock();
9697
$mock
97-
->expects($this->once())
98+
->expects(self::once())
9899
->method('__invoke')
99-
->with($this->identicalTo(2));
100+
->with(self::identicalTo(2));
100101

101102
$d1 = new Deferred();
102103
$d2 = new Deferred();

tests/FunctionCheckTypehintTest.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,79 @@
22

33
namespace React\Promise;
44

5+
use Exception;
6+
use InvalidArgumentException;
7+
58
class FunctionCheckTypehintTest extends TestCase
69
{
710
/** @test */
811
public function shouldAcceptClosureCallbackWithTypehint()
912
{
10-
$this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) {}, new \InvalidArgumentException()));
11-
$this->assertFalse(_checkTypehint(function (\InvalidArgumentException $e) {}, new \Exception()));
13+
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {}, new InvalidArgumentException()));
14+
self::assertFalse(_checkTypehint(function (InvalidArgumentException $e) {}, new Exception()));
1215
}
1316

1417
/** @test */
1518
public function shouldAcceptFunctionStringCallbackWithTypehint()
1619
{
17-
$this->assertTrue(_checkTypehint('React\Promise\testCallbackWithTypehint', new \InvalidArgumentException()));
18-
$this->assertFalse(_checkTypehint('React\Promise\testCallbackWithTypehint', new \Exception()));
20+
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
21+
self::assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new Exception()));
1922
}
2023

2124
/** @test */
2225
public function shouldAcceptInvokableObjectCallbackWithTypehint()
2326
{
24-
$this->assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new \InvalidArgumentException()));
25-
$this->assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception()));
27+
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
28+
self::assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new Exception()));
2629
}
2730

2831
/** @test */
2932
public function shouldAcceptObjectMethodCallbackWithTypehint()
3033
{
31-
$this->assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
32-
$this->assertFalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception()));
34+
self::assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new InvalidArgumentException()));
35+
self::assertFalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new Exception()));
3336
}
3437

3538
/** @test */
3639
public function shouldAcceptStaticClassCallbackWithTypehint()
3740
{
38-
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
39-
$this->assertFalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception()));
41+
self::assertTrue(_checkTypehint([TestCallbackWithTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
42+
self::assertFalse(_checkTypehint([TestCallbackWithTypehintClass::class, 'testCallbackStatic'], new Exception()));
4043
}
4144

4245
/** @test */
4346
public function shouldAcceptClosureCallbackWithoutTypehint()
4447
{
45-
$this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) {
46-
}, new \InvalidArgumentException()));
48+
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {
49+
}, new InvalidArgumentException()));
4750
}
4851

4952
/** @test */
5053
public function shouldAcceptFunctionStringCallbackWithoutTypehint()
5154
{
52-
$this->assertTrue(_checkTypehint('React\Promise\testCallbackWithoutTypehint', new \InvalidArgumentException()));
55+
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
5356
}
5457

5558
/** @test */
5659
public function shouldAcceptInvokableObjectCallbackWithoutTypehint()
5760
{
58-
$this->assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new \InvalidArgumentException()));
61+
self::assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new InvalidArgumentException()));
5962
}
6063

6164
/** @test */
6265
public function shouldAcceptObjectMethodCallbackWithoutTypehint()
6366
{
64-
$this->assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
67+
self::assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new InvalidArgumentException()));
6568
}
6669

6770
/** @test */
6871
public function shouldAcceptStaticClassCallbackWithoutTypehint()
6972
{
70-
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithoutTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
73+
self::assertTrue(_checkTypehint([TestCallbackWithoutTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
7174
}
7275
}
7376

74-
function testCallbackWithTypehint(\InvalidArgumentException $e)
77+
function testCallbackWithTypehint(InvalidArgumentException $e)
7578
{
7679
}
7780

@@ -81,15 +84,15 @@ function testCallbackWithoutTypehint()
8184

8285
class TestCallbackWithTypehintClass
8386
{
84-
public function __invoke(\InvalidArgumentException $e)
87+
public function __invoke(InvalidArgumentException $e)
8588
{
8689
}
8790

88-
public function testCallback(\InvalidArgumentException $e)
91+
public function testCallback(InvalidArgumentException $e)
8992
{
9093
}
9194

92-
public static function testCallbackStatic(\InvalidArgumentException $e)
95+
public static function testCallbackStatic(InvalidArgumentException $e)
9396
{
9497
}
9598
}

0 commit comments

Comments
 (0)