summaryrefslogtreecommitdiff
path: root/tests/Unit/Middleware/SendResponseHandlerTest.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2018-09-04 18:24:11 +0200
committermsquare <msquare@notrademark.de>2018-09-04 18:24:11 +0200
commitb320fc779063ee80b8f0ba505cb323287ccccbf5 (patch)
tree1e420597ae72c979361bf29b66ae7e27c73cf431 /tests/Unit/Middleware/SendResponseHandlerTest.php
parent9f1ee0c6c6497d43fb275491ec53fda420f64b81 (diff)
parent36dafdb68acbde2fe42ce36ef50f497c8c06411f (diff)
Merge branch 'MyIgel-rebuild-psr7'
Diffstat (limited to 'tests/Unit/Middleware/SendResponseHandlerTest.php')
-rw-r--r--tests/Unit/Middleware/SendResponseHandlerTest.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/Unit/Middleware/SendResponseHandlerTest.php b/tests/Unit/Middleware/SendResponseHandlerTest.php
new file mode 100644
index 00000000..7431299e
--- /dev/null
+++ b/tests/Unit/Middleware/SendResponseHandlerTest.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware;
+
+use Engelsystem\Middleware\SendResponseHandler;
+use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+class SendResponseHandlerTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Middleware\SendResponseHandler::process
+ */
+ public function testRegister()
+ {
+ /** @var SendResponseHandler|MockObject $middleware */
+ $middleware = $this->getMockBuilder(SendResponseHandler::class)
+ ->setMethods(['headersSent', 'sendHeader'])
+ ->getMock();
+ /** @var ServerRequestInterface|MockObject $request */
+ $request = $this->getMockForAbstractClass(ServerRequestInterface::class);
+ /** @var ResponseInterface|MockObject $response */
+ $response = $this->getMockForAbstractClass(ResponseInterface::class);
+ /** @var RequestHandlerInterface|MockObject $handler */
+ $handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
+
+ $middleware->expects($this->atLeastOnce())
+ ->method('headersSent')
+ ->willReturnOnConsecutiveCalls(true, false);
+
+ $middleware->expects($this->exactly(4))
+ ->method('sendHeader')
+ ->withConsecutive(
+ ['HTTP/0.7 505 Something went wrong!', true, 505],
+ ['Foo: bar', false],
+ ['lorem: ipsum', false],
+ ['lorem: dolor', false]
+ );
+
+ $handler->expects($this->exactly(2))
+ ->method('handle')
+ ->with($request)
+ ->willReturn($response);
+
+ $response->expects($this->exactly(2))
+ ->method('getBody')
+ ->willReturn('Lorem Ipsum!');
+
+ $response->expects($this->atLeastOnce())
+ ->method('getProtocolVersion')
+ ->willReturn('0.7');
+
+ $response->expects($this->atLeastOnce())
+ ->method('getStatusCode')
+ ->willReturn(505);
+
+ $response->expects($this->once())
+ ->method('getReasonPhrase')
+ ->willReturn('Something went wrong!');
+ $response->expects($this->once())
+ ->method('getHeaders')
+ ->willReturn(['Foo' => ['bar'], 'lorem' => ['ipsum', 'dolor']]);
+
+ $this->expectOutputString('Lorem Ipsum!Lorem Ipsum!');
+ $middleware->process($request, $handler);
+ $middleware->process($request, $handler);
+ }
+}