Passed
Pull Request — master (#225)
by
unknown
17:44 queued 07:08
created

NotFoundHandlerTest::testShouldReturnCode404()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yiisoft\Yii\Web\Tests\RequestHandler;
4
5
use Nyholm\Psr7\Factory\Psr17Factory;
6
use Nyholm\Psr7\ServerRequest;
7
use PHPUnit\Framework\TestCase;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Yiisoft\Http\Method;
10
use Yiisoft\Yii\Web\RequestHandler\NotFoundHandler;
11
12
final class NotFoundHandlerTest extends TestCase
13
{
14
    public function testShouldReturnCode404(): void
15
    {
16
        $response = $this->createHandler()->handle($this->createRequest());
17
        $this->assertEquals(404, $response->getStatusCode());
18
    }
19
20
    public function testShouldReturnCorrectErrorInBody(): void
21
    {
22
        $response = $this->createHandler()->handle($this->createRequest('http://site.com/test/path?param=1'));
23
        $this->assertEquals('We were unable to find the page /test/path.', (string)$response->getBody());
24
    }
25
26
    private function createHandler(): NotFoundHandler
27
    {
28
        return new NotFoundHandler(new Psr17Factory());
29
    }
30
31
    private function createRequest(string $uri = '/'): ServerRequestInterface
32
    {
33
        return new ServerRequest(Method::GET, $uri);
34
    }
35
}
36