14
14
15
15
class AsyncTest extends TestCase
16
16
{
17
- public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsValue ()
17
+ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsValue (): void
18
18
{
19
19
$ promise = async (function () {
20
20
return 42 ;
@@ -28,7 +28,7 @@ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsV
28
28
$ this ->assertEquals (42 , $ value );
29
29
}
30
30
31
- public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsPromiseThatFulfillsWithValue ()
31
+ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsPromiseThatFulfillsWithValue (): void
32
32
{
33
33
$ promise = async (function () {
34
34
return resolve (42 );
@@ -42,7 +42,7 @@ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsP
42
42
$ this ->assertEquals (42 , $ value );
43
43
}
44
44
45
- public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackThrows ()
45
+ public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackThrows (): void
46
46
{
47
47
$ promise = async (function () {
48
48
throw new \RuntimeException ('Foo ' , 42 );
@@ -59,7 +59,7 @@ public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackThrow
59
59
$ this ->assertEquals (42 , $ exception ->getCode ());
60
60
}
61
61
62
- public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackReturnsPromiseThatRejectsWithException ()
62
+ public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackReturnsPromiseThatRejectsWithException (): void
63
63
{
64
64
$ promise = async (function () {
65
65
return reject (new \RuntimeException ('Foo ' , 42 ));
@@ -76,7 +76,7 @@ public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackRetur
76
76
$ this ->assertEquals (42 , $ exception ->getCode ());
77
77
}
78
78
79
- public function testAsyncReturnsPendingPromiseWhenCallbackReturnsPendingPromise ()
79
+ public function testAsyncReturnsPendingPromiseWhenCallbackReturnsPendingPromise (): void
80
80
{
81
81
$ promise = async (function () {
82
82
return new Promise (function () { });
@@ -85,7 +85,7 @@ public function testAsyncReturnsPendingPromiseWhenCallbackReturnsPendingPromise(
85
85
$ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
86
86
}
87
87
88
- public function testAsyncWithAwaitReturnsReturnsPromiseFulfilledWithValueImmediatelyWhenPromiseIsFulfilled ()
88
+ public function testAsyncWithAwaitReturnsReturnsPromiseFulfilledWithValueImmediatelyWhenPromiseIsFulfilled (): void
89
89
{
90
90
$ deferred = new Deferred ();
91
91
@@ -105,7 +105,7 @@ public function testAsyncWithAwaitReturnsReturnsPromiseFulfilledWithValueImmedia
105
105
$ this ->assertEquals (42 , $ return );
106
106
}
107
107
108
- public function testAsyncWithAwaitReturnsPromiseRejectedWithExceptionImmediatelyWhenPromiseIsRejected ()
108
+ public function testAsyncWithAwaitReturnsPromiseRejectedWithExceptionImmediatelyWhenPromiseIsRejected (): void
109
109
{
110
110
$ deferred = new Deferred ();
111
111
@@ -122,13 +122,13 @@ public function testAsyncWithAwaitReturnsPromiseRejectedWithExceptionImmediately
122
122
123
123
$ deferred ->reject (new \RuntimeException ('Test ' , 42 ));
124
124
125
+ /** @var \RuntimeException $exception */
125
126
$ this ->assertInstanceof (\RuntimeException::class, $ exception );
126
- assert ($ exception instanceof \RuntimeException);
127
127
$ this ->assertEquals ('Test ' , $ exception ->getMessage ());
128
128
$ this ->assertEquals (42 , $ exception ->getCode ());
129
129
}
130
130
131
- public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsAfterAwaitingPromise ()
131
+ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsAfterAwaitingPromise (): void
132
132
{
133
133
$ promise = async (function () {
134
134
$ promise = new Promise (function ($ resolve ) {
@@ -143,23 +143,23 @@ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsA
143
143
$ this ->assertEquals (42 , $ value );
144
144
}
145
145
146
- public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackThrowsAfterAwaitingPromise ()
146
+ public function testAsyncReturnsPromiseThatRejectsWithExceptionWhenCallbackThrowsAfterAwaitingPromise (): void
147
147
{
148
148
$ promise = async (function () {
149
149
$ promise = new Promise (function ($ _ , $ reject ) {
150
150
Loop::addTimer (0.001 , fn () => $ reject (new \RuntimeException ('Foo ' , 42 )));
151
151
});
152
152
153
153
return await ($ promise );
154
- })();
154
+ })(42 );
155
155
156
156
$ this ->expectException (\RuntimeException::class);
157
157
$ this ->expectExceptionMessage ('Foo ' );
158
158
$ this ->expectExceptionCode (42 );
159
159
await ($ promise );
160
160
}
161
161
162
- public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsAfterAwaitingTwoConcurrentPromises ()
162
+ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsAfterAwaitingTwoConcurrentPromises (): void
163
163
{
164
164
$ promise1 = async (function () {
165
165
$ promise = new Promise (function ($ resolve ) {
@@ -174,6 +174,7 @@ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsA
174
174
Loop::addTimer (0.11 , fn () => $ resolve ($ theAnswerToLifeTheUniverseAndEverything ));
175
175
});
176
176
177
+ /** @var int */
177
178
return await ($ promise );
178
179
})(42 );
179
180
@@ -186,7 +187,7 @@ public function testAsyncReturnsPromiseThatFulfillsWithValueWhenCallbackReturnsA
186
187
$ this ->assertLessThan (0.12 , $ time );
187
188
}
188
189
189
- public function testCancelAsyncWillReturnRejectedPromiseWhenCancellingPendingPromiseRejects ()
190
+ public function testCancelAsyncWillReturnRejectedPromiseWhenCancellingPendingPromiseRejects (): void
190
191
{
191
192
$ promise = async (function () {
192
193
await (new Promise (function () { }, function () {
@@ -200,7 +201,7 @@ public function testCancelAsyncWillReturnRejectedPromiseWhenCancellingPendingPro
200
201
$ promise ->then (null , $ this ->expectCallableOnceWith (new \RuntimeException ('Operation cancelled ' )));
201
202
}
202
203
203
- public function testCancelAsyncWillReturnFulfilledPromiseWhenCancellingPendingPromiseRejectsInsideCatchThatReturnsValue ()
204
+ public function testCancelAsyncWillReturnFulfilledPromiseWhenCancellingPendingPromiseRejectsInsideCatchThatReturnsValue (): void
204
205
{
205
206
$ promise = async (function () {
206
207
try {
@@ -218,7 +219,7 @@ public function testCancelAsyncWillReturnFulfilledPromiseWhenCancellingPendingPr
218
219
$ promise ->then ($ this ->expectCallableOnceWith (42 ));
219
220
}
220
221
221
- public function testCancelAsycWillReturnPendigPromiseWhenCancellingFirstPromiseRejectsInsideCatchThatAwaitsSecondPromise ()
222
+ public function testCancelAsycWillReturnPendigPromiseWhenCancellingFirstPromiseRejectsInsideCatchThatAwaitsSecondPromise (): void
222
223
{
223
224
$ promise = async (function () {
224
225
try {
@@ -238,7 +239,7 @@ public function testCancelAsycWillReturnPendigPromiseWhenCancellingFirstPromiseR
238
239
$ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
239
240
}
240
241
241
- public function testCancelAsyncWillCancelNestedAwait ()
242
+ public function testCancelAsyncWillCancelNestedAwait (): void
242
243
{
243
244
self ::expectOutputString ('abc ' );
244
245
$ this ->expectException (\RuntimeException::class);
0 commit comments