summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-27 11:11:37 +0100
committermsquare <msquare@notrademark.de>2018-11-21 19:24:36 +0100
commitfd37c9d60ea818dc9a562fa88ff5f9a50132506f (patch)
tree39bc7af1141f10603164b350b9588188ccc04b4e /tests
parent23c0fae36fb8159bcf8b95bae98555201146457e (diff)
Added additional headers
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Middleware/AddHeadersTest.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/Unit/Middleware/AddHeadersTest.php b/tests/Unit/Middleware/AddHeadersTest.php
new file mode 100644
index 00000000..1a1a9e71
--- /dev/null
+++ b/tests/Unit/Middleware/AddHeadersTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware;
+
+use Engelsystem\Config\Config;
+use Engelsystem\Http\Response;
+use Engelsystem\Middleware\AddHeaders;
+use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+class AddHeadersTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Middleware\AddHeaders::__construct
+ * @covers \Engelsystem\Middleware\AddHeaders::process
+ */
+ public function testRegister()
+ {
+ /** @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());
+ }
+}