1<?php 2 3namespace React\Promise\PromiseTest; 4 5trait PromiseSettledTestTrait 6{ 7 /** 8 * @return \React\Promise\PromiseAdapter\PromiseAdapterInterface 9 */ 10 abstract public function getPromiseTestAdapter(callable $canceller = null); 11 12 /** @test */ 13 public function thenShouldReturnAPromiseForSettledPromise() 14 { 15 $adapter = $this->getPromiseTestAdapter(); 16 17 $adapter->settle(); 18 $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->then()); 19 } 20 21 /** @test */ 22 public function thenShouldReturnAllowNullForSettledPromise() 23 { 24 $adapter = $this->getPromiseTestAdapter(); 25 26 $adapter->settle(); 27 $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->then(null, null, null)); 28 } 29 30 /** @test */ 31 public function cancelShouldReturnNullForSettledPromise() 32 { 33 $adapter = $this->getPromiseTestAdapter(); 34 35 $adapter->settle(); 36 37 $this->assertNull($adapter->promise()->cancel()); 38 } 39 40 /** @test */ 41 public function cancelShouldHaveNoEffectForSettledPromise() 42 { 43 $adapter = $this->getPromiseTestAdapter($this->expectCallableNever()); 44 45 $adapter->settle(); 46 47 $adapter->promise()->cancel(); 48 } 49 50 /** @test */ 51 public function doneShouldReturnNullForSettledPromise() 52 { 53 $adapter = $this->getPromiseTestAdapter(); 54 55 $adapter->settle(); 56 $this->assertNull($adapter->promise()->done(null, function () {})); 57 } 58 59 /** @test */ 60 public function doneShouldReturnAllowNullForSettledPromise() 61 { 62 $adapter = $this->getPromiseTestAdapter(); 63 64 $adapter->settle(); 65 $this->assertNull($adapter->promise()->done(null, function () {}, null)); 66 } 67 68 /** @test */ 69 public function progressShouldNotInvokeProgressHandlerForSettledPromise() 70 { 71 $adapter = $this->getPromiseTestAdapter(); 72 73 $adapter->settle(); 74 $adapter->promise()->progress($this->expectCallableNever()); 75 $adapter->notify(); 76 } 77 78 /** @test */ 79 public function alwaysShouldReturnAPromiseForSettledPromise() 80 { 81 $adapter = $this->getPromiseTestAdapter(); 82 83 $adapter->settle(); 84 $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->always(function () {})); 85 } 86} 87