summaryrefslogtreecommitdiff
path: root/tests/Unit/Http
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Http')
-rw-r--r--tests/Unit/Http/ResponseTest.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/Unit/Http/ResponseTest.php b/tests/Unit/Http/ResponseTest.php
index f6c24767..d7dc37c0 100644
--- a/tests/Unit/Http/ResponseTest.php
+++ b/tests/Unit/Http/ResponseTest.php
@@ -3,6 +3,8 @@
namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Http\Response;
+use Engelsystem\Renderer\Renderer;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
@@ -46,4 +48,37 @@ class ResponseTest extends TestCase
$this->assertNotEquals($response, $newResponse);
$this->assertEquals('Lorem Ipsum?', $newResponse->getContent());
}
-}
+
+ /**
+ * @covers \Engelsystem\Http\Response::withView
+ */
+ public function testWithView()
+ {
+ /** @var REnderer|MockObject $renderer */
+ $renderer = $this->createMock(Renderer::class);
+
+ $renderer->expects($this->once())
+ ->method('render')
+ ->with('foo', ['lorem' => 'ipsum'])
+ ->willReturn('Foo ipsum!');
+
+ $response = new Response('', 200, [], $renderer);
+ $newResponse = $response->withView('foo', ['lorem' => 'ipsum'], 505, ['test' => 'er']);
+
+ $this->assertNotEquals($response, $newResponse);
+ $this->assertEquals('Foo ipsum!', $newResponse->getContent());
+ $this->assertEquals(505, $newResponse->getStatusCode());
+ $this->assertArraySubset(['test' => ['er']], $newResponse->getHeaders());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Response::withView
+ */
+ public function testWithViewNoRenderer()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+
+ $response = new Response();
+ $response->withView('foo');
+ }
+} \ No newline at end of file