diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-08 12:48:08 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-09 12:11:12 +0200 |
commit | 222c9fed7d4ca2b3b44c05907fbb7080c1efd342 (patch) | |
tree | 62b1bfa9233000985331b9dea703d51dc24515a2 /tests/Unit/Http | |
parent | 2d6bca1357faff28bc1f86a56b432cc463ff7574 (diff) | |
parent | 8257864829ffdfb410f05e0dd0a9c781f48b741a (diff) |
Merge remote-tracking branch 'MyIgel/templating'
Diffstat (limited to 'tests/Unit/Http')
-rw-r--r-- | tests/Unit/Http/ResponseTest.php | 37 | ||||
-rw-r--r-- | tests/Unit/Http/SessionServiceProviderTest.php | 4 | ||||
-rw-r--r-- | tests/Unit/Http/UrlGeneratorServiceProviderTest.php | 7 |
3 files changed, 45 insertions, 3 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 diff --git a/tests/Unit/Http/SessionServiceProviderTest.php b/tests/Unit/Http/SessionServiceProviderTest.php index a78b4f72..d0125bc2 100644 --- a/tests/Unit/Http/SessionServiceProviderTest.php +++ b/tests/Unit/Http/SessionServiceProviderTest.php @@ -54,6 +54,7 @@ class SessionServiceProviderTest extends ServiceProviderTest ->method('instance') ->withConsecutive( ['session.storage', $sessionStorage], + [Session::class, $session], ['session', $session] ); @@ -88,10 +89,11 @@ class SessionServiceProviderTest extends ServiceProviderTest $sessionStorage, $session ); - $app->expects($this->exactly(2)) + $app->expects($this->exactly(3)) ->method('instance') ->withConsecutive( ['session.storage', $sessionStorage], + [Session::class, $session], ['session', $session] ); diff --git a/tests/Unit/Http/UrlGeneratorServiceProviderTest.php b/tests/Unit/Http/UrlGeneratorServiceProviderTest.php index 874268b0..720af631 100644 --- a/tests/Unit/Http/UrlGeneratorServiceProviderTest.php +++ b/tests/Unit/Http/UrlGeneratorServiceProviderTest.php @@ -21,7 +21,12 @@ class UrlGeneratorServiceProviderTest extends ServiceProviderTest $app = $this->getApp(); $this->setExpects($app, 'make', [UrlGenerator::class], $urlGenerator); - $this->setExpects($app, 'instance', ['http.urlGenerator', $urlGenerator]); + $app->expects($this->exactly(2)) + ->method('instance') + ->withConsecutive( + [UrlGenerator::class, $urlGenerator], + ['http.urlGenerator', $urlGenerator] + ); $serviceProvider = new UrlGeneratorServiceProvider($app); $serviceProvider->register(); |