PluginProbe
WP-Stateless – Google Cloud Storage / 2.1.4
WP-Stateless – Google Cloud Storage v2.1.4
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / Google / vendor / react / promise / tests / CancellationQueueTest.php

CancellationQueueTest.php in WP-Stateless – Google Cloud Storage 2.1.4, at lib/Google/vendor/react/promise/tests/CancellationQueueTest.php

101 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace React\Promise;
4
5 class CancellationQueueTest extends TestCase
6 {
7 /** @test */
8 public function acceptsSimpleCancellableThenable()
9 {
10 $p = new SimpleTestCancellableThenable();
11
12 $cancellationQueue = new CancellationQueue();
13 $cancellationQueue->enqueue($p);
14
15 $cancellationQueue();
16
17 $this->assertTrue($p->cancelCalled);
18 }
19
20 /** @test */
21 public function ignoresSimpleCancellable()
22 {
23 $p = new SimpleTestCancellable();
24
25 $cancellationQueue = new CancellationQueue();
26 $cancellationQueue->enqueue($p);
27
28 $cancellationQueue();
29
30 $this->assertFalse($p->cancelCalled);
31 }
32
33 /** @test */
34 public function callsCancelOnPromisesEnqueuedBeforeStart()
35 {
36 $d1 = $this->getCancellableDeferred();
37 $d2 = $this->getCancellableDeferred();
38
39 $cancellationQueue = new CancellationQueue();
40 $cancellationQueue->enqueue($d1->promise());
41 $cancellationQueue->enqueue($d2->promise());
42
43 $cancellationQueue();
44 }
45
46 /** @test */
47 public function callsCancelOnPromisesEnqueuedAfterStart()
48 {
49 $d1 = $this->getCancellableDeferred();
50 $d2 = $this->getCancellableDeferred();
51
52 $cancellationQueue = new CancellationQueue();
53
54 $cancellationQueue();
55
56 $cancellationQueue->enqueue($d2->promise());
57 $cancellationQueue->enqueue($d1->promise());
58 }
59
60 /** @test */
61 public function doesNotCallCancelTwiceWhenStartedTwice()
62 {
63 $d = $this->getCancellableDeferred();
64
65 $cancellationQueue = new CancellationQueue();
66 $cancellationQueue->enqueue($d->promise());
67
68 $cancellationQueue();
69 $cancellationQueue();
70 }
71
72 /** @test */
73 public function rethrowsExceptionsThrownFromCancel()
74 {
75 $this->setExpectedException('\Exception', 'test');
76
77 $mock = $this
78 ->getMockBuilder('React\Promise\CancellablePromiseInterface')
79 ->getMock();
80 $mock
81 ->expects($this->once())
82 ->method('cancel')
83 ->will($this->throwException(new \Exception('test')));
84
85 $cancellationQueue = new CancellationQueue();
86 $cancellationQueue->enqueue($mock);
87
88 $cancellationQueue();
89 }
90
91 private function getCancellableDeferred()
92 {
93 $mock = $this->createCallableMock();
94 $mock
95 ->expects($this->once())
96 ->method('__invoke');
97
98 return new Deferred($mock);
99 }
100 }
101