summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controllers/AuthControllerTest.php42
-rw-r--r--tests/Unit/Controllers/CreditsControllerTest.php2
-rw-r--r--tests/Unit/Http/ResponseTest.php19
-rw-r--r--tests/Unit/Http/UrlGeneratorServiceProviderTest.php4
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);