RejectionExceptionTest.php 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace GuzzleHttp\Promise\Tests;
  3. use GuzzleHttp\Promise\RejectionException;
  4. use PHPUnit\Framework\TestCase;
  5. class Thing1
  6. {
  7. public function __construct($message)
  8. {
  9. $this->message = $message;
  10. }
  11. public function __toString()
  12. {
  13. return $this->message;
  14. }
  15. }
  16. class Thing2 implements \JsonSerializable
  17. {
  18. public function jsonSerialize()
  19. {
  20. return '{}';
  21. }
  22. }
  23. /**
  24. * @covers GuzzleHttp\Promise\RejectionException
  25. */
  26. class RejectionExceptionTest extends TestCase
  27. {
  28. public function testCanGetReasonFromException()
  29. {
  30. $thing = new Thing1('foo');
  31. $e = new RejectionException($thing);
  32. $this->assertSame($thing, $e->getReason());
  33. $this->assertEquals('The promise was rejected with reason: foo', $e->getMessage());
  34. }
  35. public function testCanGetReasonMessageFromJson()
  36. {
  37. $reason = new Thing2();
  38. $e = new RejectionException($reason);
  39. $this->assertContains("{}", $e->getMessage());
  40. }
  41. }