@@ -18,6 +18,8 @@ assertions for testing ReactPHP promises.
18
18
- [ assertPromiseFulfillsWithInstanceOf()] ( #assertpromisefulfillswithinstanceof )
19
19
- [ assertPromiseRejects()] ( #assertpromiserejects() )
20
20
- [ assertPromiseRejectsWith()] ( #assertpromiserejectswith )
21
+ - [ assertTrueAboutPromise] ( #asserttrueaboutpromise )
22
+ - [ assertFalseAboutPromise] ( #assertfalseaboutpromise )
21
23
22
24
- [ Helpers] ( #helpers )
23
25
- [ waitForPromiseToFulfill()] ( #waitforpromisetofulfill )
@@ -267,6 +269,81 @@ Failed asserting that promise rejects with a specified reason.
267
269
Failed asserting that LogicException Object (...) is an instance of class " InvalidArgumentException" .
268
270
```
269
271
272
+ ### assertTrueAboutPromise()
273
+ ` assertTrueAboutPromise(PromiseInterface $promise, callable $predicate, int $timeout = null): void `
274
+
275
+ The test fails if the value encapsulated in the Promise does not conform to an arbitrary predicate.
276
+
277
+ You can specify ` $timeout ` in seconds to wait for promise to be resolved.
278
+ If the promise was not fulfilled in specified timeout, it rejects with ` React\Promise\Timer\TimeoutException ` .
279
+ When not specified, timeout is set to 2 seconds.
280
+
281
+ ``` php
282
+ final class AssertTrueAboutPromiseTest extends TestCase
283
+ {
284
+ /** @test */
285
+ public function promise_encapsulates_integer(): void
286
+ {
287
+ $deferred = new Deferred();
288
+ $deferred->resolve(23);
289
+
290
+ $this->assertTrueAboutPromise($deferred->promise(), function ($val) {
291
+ return is_object($val);
292
+ });
293
+ }
294
+ }
295
+ ```
296
+
297
+ ``` bash
298
+ PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
299
+
300
+ F 1 / 1 (100%)
301
+
302
+ Time: 136 ms, Memory: 4.00MB
303
+
304
+ There was 1 failure:
305
+
306
+ 1) seregazhuk\R eact\P romiseTesting\t ests\A ssertTrueAboutPromiseTest::promise_encapsulates_integer
307
+ Failed asserting that false is true.
308
+ ```
309
+
310
+ ### assertFalseAboutPromise()
311
+ ` assertFalseAboutPromise(PromiseInterface $promise, callable $predicate, int $timeout = null): void `
312
+
313
+ The test fails if the value encapsulated in the Promise conforms to an arbitrary predicate.
314
+
315
+ You can specify ` $timeout ` in seconds to wait for promise to be resolved.
316
+ If the promise was not fulfilled in specified timeout, it rejects with ` React\Promise\Timer\TimeoutException ` .
317
+ When not specified, timeout is set to 2 seconds.
318
+
319
+ ``` php
320
+ final class AssertFalseAboutPromiseTest extends TestCase
321
+ {
322
+ /** @test */
323
+ public function promise_encapsulates_object(): void
324
+ {
325
+ $deferred = new Deferred();
326
+ $deferred->resolve(23);
327
+
328
+ $this->assertFalseAboutPromise($deferred->promise(), function ($val) {
329
+ return is_int($val);
330
+ });
331
+ }
332
+ }
333
+ ```
334
+
335
+ ``` bash
336
+ PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
337
+
338
+ F 1 / 1 (100%)
339
+
340
+ Time: 136 ms, Memory: 4.00MB
341
+
342
+ There was 1 failure:
343
+
344
+ 1) seregazhuk\R eact\P romiseTesting\t ests\A ssertFalseAboutPromiseTest::promise_encapsulates_object
345
+ Failed asserting that true is false.
346
+ ```
270
347
271
348
## Helpers
272
349
0 commit comments