Passed
Pull Request — master (#11)
by Derek Stephen
10:44 queued 39s
created

Psr15ToSymfonyBridgeTest.php$0 ➔ handle()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
<?php
2
3
namespace TheCodingMachine\Tests\Psr15Bridge;
4
5
use PHPUnit\Framework\TestCase;
6
use Psr\Http\Server\RequestHandlerInterface;
7
use Symfony\Component\HttpKernel\HttpKernelInterface;
8
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
9
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
10
use TheCodingMachine\Psr15Bridge\Psr15ToSymfonyBridge;
11
use Zend\Diactoros\ServerRequest;
12
use Zend\Diactoros\Uri;
13
14
class Psr15ToSymfonyBridgeTest extends TestCase
15
{
16
    public function testProcess()
17
    {
18
        // Symfony middleware that returns 'foo'
19
        $symfonyMiddleware = new class implements HttpKernelInterface
20
         {
21
             public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
22
             {
23
                 return new SymfonyResponse('foo');
24
             }
25
         };
26
27
        $delegate = $this->createMock(RequestHandlerInterface::class);
28
29
        $bridge = new Psr15ToSymfonyBridge($symfonyMiddleware);
30
31
        $request = new ServerRequest([], [], new Uri('/'), 'GET');
32
        $response = $bridge->process($request, $delegate);
0 ignored issues
show
Documentation introduced by
$delegate 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...
33
34
        $this->assertEquals('foo', (string) $response->getBody());
35
    }
36
}
37