aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/LogoutControllerTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-20 12:43:40 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commitdd09ec52b20b4a548ecf5c847627575e506e3a50 (patch)
treeb598b84727df2c604622b4db1dfee831dc7c5dca /tests/front/controller/LogoutControllerTest.php
parent5ec4708ced1cdca01eddd7e52377ab5e5f8b3290 (diff)
downloadShaarli-dd09ec52b20b4a548ecf5c847627575e506e3a50.tar.gz
Shaarli-dd09ec52b20b4a548ecf5c847627575e506e3a50.tar.zst
Shaarli-dd09ec52b20b4a548ecf5c847627575e506e3a50.zip
Refactor front controller tests to create container mock using a trait
Diffstat (limited to 'tests/front/controller/LogoutControllerTest.php')
-rw-r--r--tests/front/controller/LogoutControllerTest.php19
1 files changed, 8 insertions, 11 deletions
diff --git a/tests/front/controller/LogoutControllerTest.php b/tests/front/controller/LogoutControllerTest.php
index d9ca1c25..8e01c367 100644
--- a/tests/front/controller/LogoutControllerTest.php
+++ b/tests/front/controller/LogoutControllerTest.php
@@ -12,8 +12,6 @@ if (!function_exists('Shaarli\Front\Controller\setcookie')) {
12} 12}
13 13
14use PHPUnit\Framework\TestCase; 14use PHPUnit\Framework\TestCase;
15use Shaarli\Container\ShaarliContainer;
16use Shaarli\Render\PageCacheManager;
17use Shaarli\Security\LoginManager; 15use Shaarli\Security\LoginManager;
18use Shaarli\Security\SessionManager; 16use Shaarli\Security\SessionManager;
19use Slim\Http\Request; 17use Slim\Http\Request;
@@ -21,15 +19,15 @@ use Slim\Http\Response;
21 19
22class LogoutControllerTest extends TestCase 20class LogoutControllerTest extends TestCase
23{ 21{
24 /** @var ShaarliContainer */ 22 use FrontControllerMockHelper;
25 protected $container;
26 23
27 /** @var LogoutController */ 24 /** @var LogoutController */
28 protected $controller; 25 protected $controller;
29 26
30 public function setUp(): void 27 public function setUp(): void
31 { 28 {
32 $this->container = $this->createMock(ShaarliContainer::class); 29 $this->createContainer();
30
33 $this->controller = new LogoutController($this->container); 31 $this->controller = new LogoutController($this->container);
34 32
35 setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there'); 33 setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there');
@@ -37,16 +35,15 @@ class LogoutControllerTest extends TestCase
37 35
38 public function testValidControllerInvoke(): void 36 public function testValidControllerInvoke(): void
39 { 37 {
38 $this->createValidContainerMockSet();
39
40 $request = $this->createMock(Request::class); 40 $request = $this->createMock(Request::class);
41 $response = new Response(); 41 $response = new Response();
42 42
43 $pageCacheManager = $this->createMock(PageCacheManager::class); 43 $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches');
44 $pageCacheManager->expects(static::once())->method('invalidateCaches');
45 $this->container->pageCacheManager = $pageCacheManager;
46 44
47 $sessionManager = $this->createMock(SessionManager::class); 45 $this->container->sessionManager = $this->createMock(SessionManager::class);
48 $sessionManager->expects(static::once())->method('logout'); 46 $this->container->sessionManager->expects(static::once())->method('logout');
49 $this->container->sessionManager = $sessionManager;
50 47
51 static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); 48 static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]);
52 49