for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace TheCodingMachine\Tests\Psr15Bridge;
use PHPUnit\Framework\TestCase;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use TheCodingMachine\Psr15Bridge\Psr15ToSymfonyBridge;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri;
class Psr15ToSymfonyBridgeTest extends TestCase
{
public function testProcess()
// Symfony middleware that returns 'foo'
$symfonyMiddleware = new class implements HttpKernelInterface
public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
return new SymfonyResponse('foo');
}
};
$delegate = $this->createMock(RequestHandlerInterface::class);
$bridge = new Psr15ToSymfonyBridge($symfonyMiddleware);
$request = new ServerRequest([], [], new Uri('/'), 'GET');
$response = $bridge->process($request, $delegate);
$delegate
object<PHPUnit\Framework\MockObject\MockObject>
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);
$this->assertEquals('foo', (string) $response->getBody());
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: