diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-10-25 18:53:05 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2019-06-12 10:24:02 +0200 |
commit | 6ed891fc0416e8025f929cf60a07b1020118b221 (patch) | |
tree | 17e6a0d312693838133cb8241320424b9c0fcd1e /tests/Unit | |
parent | 2e51fbff9d8472a0e98af39aff52d30f0b67706b (diff) |
Added logout via AuthController
Diffstat (limited to 'tests/Unit')
-rw-r--r-- | tests/Unit/Controllers/AuthControllerTest.php | 42 | ||||
-rw-r--r-- | tests/Unit/Controllers/CreditsControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Http/ResponseTest.php | 19 | ||||
-rw-r--r-- | tests/Unit/Http/UrlGeneratorServiceProviderTest.php | 4 |
4 files changed, 65 insertions, 2 deletions
diff --git a/tests/Unit/Controllers/AuthControllerTest.php b/tests/Unit/Controllers/AuthControllerTest.php new file mode 100644 index 00000000..c5349cda --- /dev/null +++ b/tests/Unit/Controllers/AuthControllerTest.php @@ -0,0 +1,42 @@ +<?php + +namespace Engelsystem\Test\Unit\Controllers; + +use Engelsystem\Controllers\AuthController; +use Engelsystem\Http\Response; +use Engelsystem\Http\UrlGeneratorInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Session\SessionInterface; + +class AuthControllerTest extends TestCase +{ + /** + * @covers \Engelsystem\Controllers\AuthController::__construct + * @covers \Engelsystem\Controllers\AuthController::logout + */ + public function testLogout() + { + /** @var Response|MockObject $response */ + $response = $this->createMock(Response::class); + /** @var SessionInterface|MockObject $session */ + $session = $this->getMockForAbstractClass(SessionInterface::class); + /** @var UrlGeneratorInterface|MockObject $url */ + $url = $this->getMockForAbstractClass(UrlGeneratorInterface::class); + + $session->expects($this->once()) + ->method('invalidate'); + + $response->expects($this->once()) + ->method('redirectTo') + ->with('https://foo.bar/'); + + $url->expects($this->once()) + ->method('to') + ->with('/') + ->willReturn('https://foo.bar/'); + + $controller = new AuthController($response, $session, $url); + $controller->logout(); + } +} diff --git a/tests/Unit/Controllers/CreditsControllerTest.php b/tests/Unit/Controllers/CreditsControllerTest.php index 3ce92cb1..42ea4ea1 100644 --- a/tests/Unit/Controllers/CreditsControllerTest.php +++ b/tests/Unit/Controllers/CreditsControllerTest.php @@ -1,6 +1,6 @@ <?php -namespace Unit\Controllers; +namespace Engelsystem\Test\Unit\Controllers; use Engelsystem\Config\Config; use Engelsystem\Controllers\CreditsController; diff --git a/tests/Unit/Http/ResponseTest.php b/tests/Unit/Http/ResponseTest.php index 6f20ff67..34f76513 100644 --- a/tests/Unit/Http/ResponseTest.php +++ b/tests/Unit/Http/ResponseTest.php @@ -85,4 +85,23 @@ class ResponseTest extends TestCase $response = new Response(); $response->withView('foo'); } + + /** + * @covers \Engelsystem\Http\Response::redirectTo + */ + public function testRedirectTo() + { + $response = new Response(); + $newResponse = $response->redirectTo('http://foo.bar/lorem', 301, ['test' => 'ing']); + + $this->assertNotEquals($response, $newResponse); + $this->assertEquals(301, $newResponse->getStatusCode()); + $this->assertArraySubset( + [ + 'location' => ['http://foo.bar/lorem'], + 'test' => ['ing'], + ], + $newResponse->getHeaders() + ); + } } diff --git a/tests/Unit/Http/UrlGeneratorServiceProviderTest.php b/tests/Unit/Http/UrlGeneratorServiceProviderTest.php index c396c05a..61bf3e7c 100644 --- a/tests/Unit/Http/UrlGeneratorServiceProviderTest.php +++ b/tests/Unit/Http/UrlGeneratorServiceProviderTest.php @@ -3,6 +3,7 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Http\UrlGenerator; +use Engelsystem\Http\UrlGeneratorInterface; use Engelsystem\Http\UrlGeneratorServiceProvider; use Engelsystem\Test\Unit\ServiceProviderTest; use PHPUnit\Framework\MockObject\MockObject; @@ -25,7 +26,8 @@ class UrlGeneratorServiceProviderTest extends ServiceProviderTest ->method('instance') ->withConsecutive( [UrlGenerator::class, $urlGenerator], - ['http.urlGenerator', $urlGenerator] + ['http.urlGenerator', $urlGenerator], + [UrlGeneratorInterface::class, $urlGenerator] ); $serviceProvider = new UrlGeneratorServiceProvider($app); |