FactoryTest::testCreateDefaultTokenGenerator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PSR7CsrfTest;
6
7
use PHPUnit\Framework\TestCase;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use PSR7Csrf\CSRFCheckerMiddleware;
12
use PSR7Csrf\Factory;
13
use PSR7Csrf\TokenGeneratorInterface;
14
15
/**
16
 * @covers \PSR7Csrf\Factory
17
 */
18
final class FactoryTest extends TestCase
19
{
20
    public function testCreateDefaultCSRFCheckerMiddleware()
21
    {
22
        $faultyResponse = $this->createMock(ResponseInterface::class);
23
24
        $middleware = Factory::createDefaultCSRFCheckerMiddleware($faultyResponse);
0 ignored issues
show
Documentation introduced by
$faultyResponse is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
26
        self::assertInstanceOf(CSRFCheckerMiddleware::class, $middleware);
27
28
        $request = $this->createMock(ServerRequestInterface::class);
29
30
        $request
31
            ->expects(self::any())
32
            ->method('getMethod')
33
            ->willReturn('POST');
34
35
        self::assertSame(
36
            $faultyResponse,
37
            $middleware->process(
38
                $request,
0 ignored issues
show
Documentation introduced by
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
                $this->createMock(RequestHandlerInterface::class)
0 ignored issues
show
Documentation introduced by
$this->createMock(\Psr\H...andlerInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Server\RequestHandlerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
            ),
41
            'Faulty http response passed to the factory is returned as part of a failed CSRF validation'
42
        );
43
    }
44
45
    public function testCreateDefaultTokenGenerator()
46
    {
47
        self::assertInstanceOf(TokenGeneratorInterface::class, Factory::createDefaultTokenGenerator());
48
    }
49
}
50