Passed
Pull Request — master (#257)
by Wilmer
25:21 queued 10:17
created

NotFoundHandlerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 22
rs 10
c 1
b 0
f 0
wmc 4
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\Http\Method;
10
use Yiisoft\Yii\Web\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