2018-10-27 12:11:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Middleware;
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
2018-10-27 12:11:37 +02:00
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Http\Response;
|
|
|
|
use Engelsystem\Middleware\AddHeaders;
|
2019-04-24 10:45:00 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-10-27 12:11:37 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
|
|
|
|
|
|
class AddHeadersTest extends TestCase
|
|
|
|
{
|
2019-04-24 10:45:00 +02:00
|
|
|
use ArraySubsetAsserts;
|
|
|
|
|
2018-10-27 12:11:37 +02:00
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Middleware\AddHeaders::__construct
|
|
|
|
* @covers \Engelsystem\Middleware\AddHeaders::process
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testRegister(): void
|
2018-10-27 12:11:37 +02:00
|
|
|
{
|
|
|
|
/** @var ServerRequestInterface|MockObject $request */
|
|
|
|
$request = $this->getMockForAbstractClass(ServerRequestInterface::class);
|
|
|
|
/** @var RequestHandlerInterface|MockObject $handler */
|
|
|
|
$handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
|
|
|
|
$response = new Response();
|
|
|
|
|
|
|
|
$handler->expects($this->atLeastOnce())
|
|
|
|
->method('handle')
|
|
|
|
->willReturn($response);
|
|
|
|
|
|
|
|
$config = new Config(['add_headers' => false]);
|
|
|
|
|
|
|
|
$middleware = new AddHeaders($config);
|
|
|
|
$this->assertEquals($response, $middleware->process($request, $handler));
|
|
|
|
|
|
|
|
$config->set('add_headers', true);
|
|
|
|
$config->set('headers', ['Foo-Header' => 'bar!']);
|
|
|
|
$return = $middleware->process($request, $handler);
|
|
|
|
|
|
|
|
$this->assertNotEquals($response, $return);
|
|
|
|
$this->assertArraySubset(['Foo-Header' => ['bar!']], $return->getHeaders());
|
|
|
|
}
|
|
|
|
}
|