1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClientTest\Exception; |
6
|
|
|
|
7
|
|
|
use Facile\OpenIDClient\Exception\ExceptionInterface; |
8
|
|
|
use Facile\OpenIDClient\Exception\RemoteException; |
9
|
|
|
use Facile\OpenIDClientTest\TestCase; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
class RemoteExceptionTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testException(): void |
15
|
|
|
{ |
16
|
|
|
$response = $this->prophesize(ResponseInterface::class); |
17
|
|
|
$response->getReasonPhrase()->willReturn('Error message'); |
18
|
|
|
$response->getStatusCode()->willReturn(400); |
19
|
|
|
|
20
|
|
|
$exception = new RemoteException($response->reveal()); |
21
|
|
|
|
22
|
|
|
static::assertInstanceOf(ExceptionInterface::class, $exception); |
23
|
|
|
static::assertSame('Error message', $exception->getMessage()); |
24
|
|
|
static::assertSame(400, $exception->getCode()); |
25
|
|
|
static::assertSame($response->reveal(), $exception->getResponse()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testExceptionWithCustomMessage(): void |
29
|
|
|
{ |
30
|
|
|
$response = $this->prophesize(ResponseInterface::class); |
31
|
|
|
$response->getReasonPhrase()->willReturn('Error message'); |
32
|
|
|
$response->getStatusCode()->willReturn(400); |
33
|
|
|
|
34
|
|
|
$exception = new RemoteException($response->reveal(), 'foo'); |
35
|
|
|
|
36
|
|
|
static::assertInstanceOf(ExceptionInterface::class, $exception); |
37
|
|
|
static::assertSame('foo', $exception->getMessage()); |
38
|
|
|
static::assertSame(400, $exception->getCode()); |
39
|
|
|
static::assertSame($response->reveal(), $exception->getResponse()); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|