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