/
HttpExceptionTest.php
52 lines (41 loc) · 1.69 KB
/
HttpExceptionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
declare(strict_types=1);
namespace Slim\Tests\Exception;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Exception\HttpMethodNotAllowedException;
use Slim\Exception\HttpNotFoundException;
use Slim\Tests\TestCase;
class HttpExceptionTest extends TestCase
{
public function testHttpExceptionRequestReponseGetterSetters()
{
$request = $this->createServerRequest('/');
$exception = new HttpNotFoundException($request);
$this->assertInstanceOf(ServerRequestInterface::class, $exception->getRequest());
}
public function testHttpExceptionAttributeGettersSetters()
{
$request = $this->createServerRequest('/');
$exception = new HttpNotFoundException($request);
$exception->setTitle('Title');
$exception->setDescription('Description');
$this->assertEquals('Title', $exception->getTitle());
$this->assertEquals('Description', $exception->getDescription());
}
public function testHttpNotAllowedExceptionGetAllowedMethods()
{
$request = $this->createServerRequest('/');
$exception = new HttpMethodNotAllowedException($request);
$exception->setAllowedMethods(['GET']);
$this->assertEquals(['GET'], $exception->getAllowedMethods());
$this->assertEquals('Method not allowed. Must be one of: GET', $exception->getMessage());
$exception = new HttpMethodNotAllowedException($request);
$this->assertEquals([], $exception->getAllowedMethods());
$this->assertEquals('Method not allowed.', $exception->getMessage());
}
}