Passed
Pull Request — master (#199)
by Rustam
02:14
created

HttpCacheTest.php$0 ➔ createRequestHandler()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 6
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A HttpCacheTest.php$0 ➔ handle() 0 3 1
1
<?php
2
3
namespace Yiisoft\Yii\Web\Tests\Middleware;
4
5
use Nyholm\Psr7\Factory\Psr17Factory;
6
use Nyholm\Psr7\Response;
7
use Nyholm\Psr7\ServerRequest;
8
use PHPUnit\Framework\TestCase;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
use Yiisoft\Router\Method;
13
use Yiisoft\Yii\Web\Middleware\HttpCache;
14
15
class HttpCacheTest extends TestCase
16
{
17
    /**
18
     * @test
19
     */
20
    public function validCacheResult(): void
21
    {
22
        $middleware = $this->createMiddlewareWithLastModified(\time());
23
        $headers = [
24
25
        ];
26
        $response = $middleware->process($this->createServerRequest(Method::GET, $headers), $this->createRequestHandler());
27
        $this->assertEquals(200, $response->getStatusCode());
28
    }
29
30
    private function createMiddlewareWithLastModified(int $lastModified)
31
    {
32
        $middleware = new HttpCache(new Psr17Factory());
33
        $middleware->setLastModified(static function (ServerRequestInterface $request, array $params) use ($lastModified) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
        $middleware->setLastModified(static function (/** @scrutinizer ignore-unused */ ServerRequestInterface $request, array $params) use ($lastModified) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
        $middleware->setLastModified(static function (ServerRequestInterface $request, /** @scrutinizer ignore-unused */ array $params) use ($lastModified) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
            return $lastModified;
35
        });
36
        return $middleware;
37
    }
38
39
    private function createRequestHandler(): RequestHandlerInterface
40
    {
41
        return new class implements RequestHandlerInterface {
42
            public function handle(ServerRequestInterface $request): ResponseInterface
43
            {
44
                return new Response(200);
45
            }
46
        };
47
    }
48
49
    private function createServerRequest(string $method = Method::GET, $headers = [])
50
    {
51
        return new ServerRequest($method, '/', $headers);
52
    }
53
}
54