Skip to content

Commit 761a765

Browse files
committed
tests: Update tests and PHPUnit to v10
1 parent 3fda7b2 commit 761a765

40 files changed

+1099
-1077
lines changed

composer.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "internal/promise",
33
"description": "A lightweight implementation of CommonJS Promises/A for PHP",
44
"license": "MIT",
5+
"keywords": [
6+
"promise",
7+
"promises"
8+
],
59
"authors": [
610
{
711
"name": "Jan Sorgalla",
@@ -28,7 +32,8 @@
2832
"php": ">=8.1"
2933
},
3034
"require-dev": {
31-
"phpunit/phpunit": "^9.6"
35+
"phpunit/phpunit": "^10.5.10",
36+
"ta-tikoma/phpunit-architecture-test": "^0.8.5"
3237
},
3338
"replace": {
3439
"react/promise": "^2.0"
@@ -49,8 +54,10 @@
4954
]
5055
}
5156
},
52-
"keywords": [
53-
"promise",
54-
"promises"
55-
]
57+
"config": {
58+
"audit": {
59+
"abandoned": "report"
60+
},
61+
"sort-packages": true
62+
}
5663
}

tests/CancellationQueueTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace React\Promise;
46

57
class CancellationQueueTest extends TestCase
68
{
7-
/** @test */
8-
public function acceptsSimpleCancellableThenable()
9+
#[\PHPUnit\Framework\Attributes\Test]
10+
public function acceptsSimpleCancellableThenable(): void
911
{
1012
$p = new SimpleTestCancellableThenable();
1113

@@ -17,8 +19,8 @@ public function acceptsSimpleCancellableThenable()
1719
$this->assertTrue($p->cancelCalled);
1820
}
1921

20-
/** @test */
21-
public function ignoresSimpleCancellable()
22+
#[\PHPUnit\Framework\Attributes\Test]
23+
public function ignoresSimpleCancellable(): void
2224
{
2325
$p = new SimpleTestCancellable();
2426

@@ -30,8 +32,8 @@ public function ignoresSimpleCancellable()
3032
$this->assertFalse($p->cancelCalled);
3133
}
3234

33-
/** @test */
34-
public function callsCancelOnPromisesEnqueuedBeforeStart()
35+
#[\PHPUnit\Framework\Attributes\Test]
36+
public function callsCancelOnPromisesEnqueuedBeforeStart(): void
3537
{
3638
$d1 = $this->getCancellableDeferred();
3739
$d2 = $this->getCancellableDeferred();
@@ -43,8 +45,8 @@ public function callsCancelOnPromisesEnqueuedBeforeStart()
4345
$cancellationQueue();
4446
}
4547

46-
/** @test */
47-
public function callsCancelOnPromisesEnqueuedAfterStart()
48+
#[\PHPUnit\Framework\Attributes\Test]
49+
public function callsCancelOnPromisesEnqueuedAfterStart(): void
4850
{
4951
$d1 = $this->getCancellableDeferred();
5052
$d2 = $this->getCancellableDeferred();
@@ -57,8 +59,8 @@ public function callsCancelOnPromisesEnqueuedAfterStart()
5759
$cancellationQueue->enqueue($d1->promise());
5860
}
5961

60-
/** @test */
61-
public function doesNotCallCancelTwiceWhenStartedTwice()
62+
#[\PHPUnit\Framework\Attributes\Test]
63+
public function doesNotCallCancelTwiceWhenStartedTwice(): void
6264
{
6365
$d = $this->getCancellableDeferred();
6466

@@ -69,8 +71,8 @@ public function doesNotCallCancelTwiceWhenStartedTwice()
6971
$cancellationQueue();
7072
}
7173

72-
/** @test */
73-
public function rethrowsExceptionsThrownFromCancel()
74+
#[\PHPUnit\Framework\Attributes\Test]
75+
public function rethrowsExceptionsThrownFromCancel(): void
7476
{
7577
$this->setExpectedException('\Exception', 'test');
7678

tests/DeferredTest.php

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace React\Promise;
46

57
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
@@ -8,7 +10,7 @@ class DeferredTest extends TestCase
810
{
911
use PromiseTest\FullTestTrait;
1012

11-
public function getPromiseTestAdapter(callable $canceller = null)
13+
public function getPromiseTestAdapter(?callable $canceller = null)
1214
{
1315
$d = new Deferred($canceller);
1416

@@ -21,8 +23,8 @@ public function getPromiseTestAdapter(callable $canceller = null)
2123
]);
2224
}
2325

24-
/** @test */
25-
public function progressIsAnAliasForNotify()
26+
#[\PHPUnit\Framework\Attributes\Test]
27+
public function progressIsAnAliasForNotify(): void
2628
{
2729
$deferred = new Deferred();
2830

@@ -40,77 +42,77 @@ public function progressIsAnAliasForNotify()
4042
$deferred->progress($sentinel);
4143
}
4244

43-
/** @test */
44-
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerRejectsWithException()
45+
#[\PHPUnit\Framework\Attributes\Test]
46+
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerRejectsWithException(): void
4547
{
46-
gc_collect_cycles();
47-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
48+
\gc_collect_cycles();
49+
\gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
4850

49-
$deferred = new Deferred(function ($resolve, $reject) {
51+
$deferred = new Deferred(static function ($resolve, $reject): void {
5052
$reject(new \Exception('foo'));
5153
});
5254
$deferred->promise()->cancel();
5355
unset($deferred);
5456

55-
$this->assertSame(0, gc_collect_cycles());
57+
$this->assertSame(0, \gc_collect_cycles());
5658
}
5759

58-
/** @test */
59-
public function shouldRejectWithoutCreatingGarbageCyclesIfParentCancellerRejectsWithException()
60+
#[\PHPUnit\Framework\Attributes\Test]
61+
public function shouldRejectWithoutCreatingGarbageCyclesIfParentCancellerRejectsWithException(): void
6062
{
61-
gc_collect_cycles();
62-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
63+
\gc_collect_cycles();
64+
\gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
6365

64-
$deferred = new Deferred(function ($resolve, $reject) {
66+
$deferred = new Deferred(static function ($resolve, $reject): void {
6567
$reject(new \Exception('foo'));
6668
});
6769
$deferred->promise()->then()->cancel();
6870
unset($deferred);
6971

70-
$this->assertSame(0, gc_collect_cycles());
72+
$this->assertSame(0, \gc_collect_cycles());
7173
}
7274

73-
/** @test */
74-
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerHoldsReferenceAndExplicitlyRejectWithException()
75+
#[\PHPUnit\Framework\Attributes\Test]
76+
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerHoldsReferenceAndExplicitlyRejectWithException(): void
7577
{
76-
gc_collect_cycles();
77-
$deferred = new Deferred(function () use (&$deferred) { });
78+
\gc_collect_cycles();
79+
$deferred = new Deferred(static function () use (&$deferred): void {});
7880
$deferred->reject(new \Exception('foo'));
7981
unset($deferred);
8082

81-
$this->assertSame(0, gc_collect_cycles());
83+
$this->assertSame(0, \gc_collect_cycles());
8284
}
8385

84-
/** @test */
85-
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferred()
86+
#[\PHPUnit\Framework\Attributes\Test]
87+
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferred(): void
8688
{
87-
gc_collect_cycles();
89+
\gc_collect_cycles();
8890
$deferred = new Deferred();
8991
$deferred->promise();
9092
unset($deferred);
9193

92-
$this->assertSame(0, gc_collect_cycles());
94+
$this->assertSame(0, \gc_collect_cycles());
9395
}
9496

95-
/** @test */
96-
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferredWithUnusedCanceller()
97+
#[\PHPUnit\Framework\Attributes\Test]
98+
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferredWithUnusedCanceller(): void
9799
{
98-
gc_collect_cycles();
99-
$deferred = new Deferred(function () { });
100+
\gc_collect_cycles();
101+
$deferred = new Deferred(static function (): void {});
100102
$deferred->promise();
101103
unset($deferred);
102104

103-
$this->assertSame(0, gc_collect_cycles());
105+
$this->assertSame(0, \gc_collect_cycles());
104106
}
105107

106-
/** @test */
107-
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferredWithNoopCanceller()
108+
#[\PHPUnit\Framework\Attributes\Test]
109+
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferredWithNoopCanceller(): void
108110
{
109-
gc_collect_cycles();
110-
$deferred = new Deferred(function () { });
111+
\gc_collect_cycles();
112+
$deferred = new Deferred(static function (): void {});
111113
$deferred->promise()->cancel();
112114
unset($deferred);
113115

114-
$this->assertSame(0, gc_collect_cycles());
116+
$this->assertSame(0, \gc_collect_cycles());
115117
}
116118
}

tests/FulfilledPromiseTest.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,80 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace React\Promise;
46

57
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
68

79
class FulfilledPromiseTest extends TestCase
810
{
9-
use PromiseTest\PromiseSettledTestTrait,
10-
PromiseTest\PromiseFulfilledTestTrait;
11+
use PromiseTest\PromiseSettledTestTrait;
12+
use PromiseTest\PromiseFulfilledTestTrait;
1113

12-
public function getPromiseTestAdapter(callable $canceller = null)
14+
public function getPromiseTestAdapter(?callable $canceller = null)
1315
{
1416
$promise = null;
1517

1618
return new CallbackPromiseAdapter([
17-
'promise' => function () use (&$promise) {
19+
'promise' => static function () use (&$promise) {
1820
if (!$promise) {
1921
throw new \LogicException('FulfilledPromise must be resolved before obtaining the promise');
2022
}
2123

2224
return $promise;
2325
},
24-
'resolve' => function ($value = null) use (&$promise) {
26+
'resolve' => static function ($value = null) use (&$promise): void {
2527
if (!$promise) {
2628
$promise = new FulfilledPromise($value);
2729
}
2830
},
29-
'reject' => function () {
31+
'reject' => static function (): void {
3032
throw new \LogicException('You cannot call reject() for React\Promise\FulfilledPromise');
3133
},
32-
'notify' => function () {
34+
'notify' => static function (): void {
3335
// no-op
3436
},
35-
'settle' => function ($value = null) use (&$promise) {
37+
'settle' => static function ($value = null) use (&$promise): void {
3638
if (!$promise) {
3739
$promise = new FulfilledPromise($value);
3840
}
3941
},
4042
]);
4143
}
4244

43-
/** @test */
45+
#[\PHPUnit\Framework\Attributes\Test]
4446
public function shouldThrowExceptionIfConstructedWithAPromise()
4547
{
4648
$this->setExpectedException('\InvalidArgumentException');
4749

4850
return new FulfilledPromise(new FulfilledPromise());
4951
}
5052

51-
/** @test */
52-
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithAlwaysFollowers()
53+
#[\PHPUnit\Framework\Attributes\Test]
54+
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithAlwaysFollowers(): void
5355
{
54-
gc_collect_cycles();
55-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
56+
\gc_collect_cycles();
57+
\gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
5658

5759
$promise = new FulfilledPromise(1);
58-
$promise->always(function () {
60+
$promise->always(static function (): void {
5961
throw new \RuntimeException();
6062
});
6163
unset($promise);
6264

63-
$this->assertSame(0, gc_collect_cycles());
65+
$this->assertSame(0, \gc_collect_cycles());
6466
}
6567

66-
/** @test */
67-
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithThenFollowers()
68+
#[\PHPUnit\Framework\Attributes\Test]
69+
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithThenFollowers(): void
6870
{
69-
gc_collect_cycles();
71+
\gc_collect_cycles();
7072
$promise = new FulfilledPromise(1);
71-
$promise = $promise->then(function () {
73+
$promise = $promise->then(static function (): void {
7274
throw new \RuntimeException();
7375
});
7476
unset($promise);
7577

76-
$this->assertSame(0, gc_collect_cycles());
78+
$this->assertSame(0, \gc_collect_cycles());
7779
}
7880
}

0 commit comments

Comments
 (0)