diff options
Diffstat (limited to 'assets/php/vendor/react/promise/tests/CancellationQueueTest.php')
-rw-r--r-- | assets/php/vendor/react/promise/tests/CancellationQueueTest.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/assets/php/vendor/react/promise/tests/CancellationQueueTest.php b/assets/php/vendor/react/promise/tests/CancellationQueueTest.php new file mode 100644 index 0000000..32cedf4 --- /dev/null +++ b/assets/php/vendor/react/promise/tests/CancellationQueueTest.php @@ -0,0 +1,100 @@ +<?php + +namespace React\Promise; + +class CancellationQueueTest extends TestCase +{ + /** @test */ + public function acceptsSimpleCancellableThenable() + { + $p = new SimpleTestCancellableThenable(); + + $cancellationQueue = new CancellationQueue(); + $cancellationQueue->enqueue($p); + + $cancellationQueue(); + + $this->assertTrue($p->cancelCalled); + } + + /** @test */ + public function ignoresSimpleCancellable() + { + $p = new SimpleTestCancellable(); + + $cancellationQueue = new CancellationQueue(); + $cancellationQueue->enqueue($p); + + $cancellationQueue(); + + $this->assertFalse($p->cancelCalled); + } + + /** @test */ + public function callsCancelOnPromisesEnqueuedBeforeStart() + { + $d1 = $this->getCancellableDeferred(); + $d2 = $this->getCancellableDeferred(); + + $cancellationQueue = new CancellationQueue(); + $cancellationQueue->enqueue($d1->promise()); + $cancellationQueue->enqueue($d2->promise()); + + $cancellationQueue(); + } + + /** @test */ + public function callsCancelOnPromisesEnqueuedAfterStart() + { + $d1 = $this->getCancellableDeferred(); + $d2 = $this->getCancellableDeferred(); + + $cancellationQueue = new CancellationQueue(); + + $cancellationQueue(); + + $cancellationQueue->enqueue($d2->promise()); + $cancellationQueue->enqueue($d1->promise()); + } + + /** @test */ + public function doesNotCallCancelTwiceWhenStartedTwice() + { + $d = $this->getCancellableDeferred(); + + $cancellationQueue = new CancellationQueue(); + $cancellationQueue->enqueue($d->promise()); + + $cancellationQueue(); + $cancellationQueue(); + } + + /** @test */ + public function rethrowsExceptionsThrownFromCancel() + { + $this->setExpectedException('\Exception', 'test'); + + $mock = $this + ->getMockBuilder('React\Promise\CancellablePromiseInterface') + ->getMock(); + $mock + ->expects($this->once()) + ->method('cancel') + ->will($this->throwException(new \Exception('test'))); + + $cancellationQueue = new CancellationQueue(); + $cancellationQueue->enqueue($mock); + + $cancellationQueue(); + } + + private function getCancellableDeferred() + { + $mock = $this->createCallableMock(); + $mock + ->expects($this->once()) + ->method('__invoke'); + + return new Deferred($mock); + } +} |