From dd09ec52b20b4a548ecf5c847627575e506e3a50 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 20 May 2020 12:43:40 +0200 Subject: Refactor front controller tests to create container mock using a trait --- tests/front/controller/LogoutControllerTest.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'tests/front/controller/LogoutControllerTest.php') 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')) { } use PHPUnit\Framework\TestCase; -use Shaarli\Container\ShaarliContainer; -use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; use Slim\Http\Request; @@ -21,15 +19,15 @@ use Slim\Http\Response; class LogoutControllerTest extends TestCase { - /** @var ShaarliContainer */ - protected $container; + use FrontControllerMockHelper; /** @var LogoutController */ protected $controller; public function setUp(): void { - $this->container = $this->createMock(ShaarliContainer::class); + $this->createContainer(); + $this->controller = new LogoutController($this->container); setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there'); @@ -37,16 +35,15 @@ class LogoutControllerTest extends TestCase public function testValidControllerInvoke(): void { + $this->createValidContainerMockSet(); + $request = $this->createMock(Request::class); $response = new Response(); - $pageCacheManager = $this->createMock(PageCacheManager::class); - $pageCacheManager->expects(static::once())->method('invalidateCaches'); - $this->container->pageCacheManager = $pageCacheManager; + $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches'); - $sessionManager = $this->createMock(SessionManager::class); - $sessionManager->expects(static::once())->method('logout'); - $this->container->sessionManager = $sessionManager; + $this->container->sessionManager = $this->createMock(SessionManager::class); + $this->container->sessionManager->expects(static::once())->method('logout'); static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); -- cgit v1.2.3