PromisePendingTestTrait.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace React\Promise\PromiseTest;
  3. use React\Promise\PromiseAdapter\PromiseAdapterInterface;
  4. use React\Promise\PromiseInterface;
  5. trait PromisePendingTestTrait
  6. {
  7. abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface;
  8. /** @test */
  9. public function thenShouldReturnAPromiseForPendingPromise(): void
  10. {
  11. $adapter = $this->getPromiseTestAdapter();
  12. self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->then());
  13. }
  14. /** @test */
  15. public function thenShouldReturnAllowNullForPendingPromise(): void
  16. {
  17. $adapter = $this->getPromiseTestAdapter();
  18. self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->then(null, null));
  19. }
  20. /** @test */
  21. public function catchShouldNotInvokeRejectionHandlerForPendingPromise(): void
  22. {
  23. $adapter = $this->getPromiseTestAdapter();
  24. $adapter->settle(null);
  25. $adapter->promise()->catch($this->expectCallableNever());
  26. }
  27. /** @test */
  28. public function finallyShouldReturnAPromiseForPendingPromise(): void
  29. {
  30. $adapter = $this->getPromiseTestAdapter();
  31. self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->finally(function () {}));
  32. }
  33. /**
  34. * @test
  35. * @deprecated
  36. */
  37. public function otherwiseShouldNotInvokeRejectionHandlerForPendingPromise(): void
  38. {
  39. $adapter = $this->getPromiseTestAdapter();
  40. $adapter->settle(null);
  41. $adapter->promise()->otherwise($this->expectCallableNever());
  42. }
  43. /**
  44. * @test
  45. * @deprecated
  46. */
  47. public function alwaysShouldReturnAPromiseForPendingPromise(): void
  48. {
  49. $adapter = $this->getPromiseTestAdapter();
  50. self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->always(function () {}));
  51. }
  52. }