Passed
Push — master ( f74aa0...4214e2 )
by Alexander
05:54
created

NotFoundHandlerTest::createHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Yiisoft\Yii\Web\Tests;
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\Router\Method;
10
use Yiisoft\Yii\Web\NotFoundHandler;
11
12
final class NotFoundHandlerTest extends TestCase
13
{
14
    /**
15
     * @test
16
     */
17
    public function shouldReturnCode404()
18
    {
19
        $response = $this->createHandler()->handle($this->createRequest());
20
        $this->assertEquals(404, $response->getStatusCode());
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function shouldReturnCorrectErrorInBody()
27
    {
28
        $response = $this->createHandler()->handle($this->createRequest('http://site.com/test/path?param=1'));
29
        $this->assertEquals('We were unable to find the page /test/path.', (string)$response->getBody());
30
    }
31
32
    private function createHandler(): NotFoundHandler
33
    {
34
        return new NotFoundHandler(new Psr17Factory());
35
    }
36
37
    private function createRequest(string $uri = '/'): ServerRequestInterface
38
    {
39
        return new ServerRequest(Method::GET, $uri);
40
    }
41
}
42