/** * Test logout() returns false if session removal fails */ public function testLogoutReturnsFalseIfSessionRemovalFailure() { $mockApp = m::mock(\Silex\Application::class)->makePartial(); $mockSessionObject = m::mock(\stdClass::class); $mockSessionObject->shouldReceive('remove')->with('commentator')->andReturn(false); $mockDataObject = m::mock(CommentatorData::class, [$mockApp]); $mockDataObject->shouldReceive('getSession')->andReturn($mockSessionObject); $object = new CommentatorApi($mockDataObject); $returned = $object->logout(); $this->assertFalse($returned); }
/** * @param Application $app * * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response */ public function logout(Application $app) { if ($this->isAdmin($app)) { $user = new AuthorApi(new AuthorData($app)); } elseif ($this->isUser($app)) { $user = new CommentatorApi(new CommentatorData($app)); } else { $app['monolog']->addError('Session found but not author nor commentator.'); $app['session']->getFlashBag()->add('message', 'Unknown logout request made.'); return $this->index($app); } $user->logout(); $app['session']->getFlashBag()->add('message', 'Successfully logged out.'); return $this->index($app); }