From dd883aaf0999e9dc783a1a19bfeeab181c949d55 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Wed, 8 Nov 2017 20:24:49 +0100 Subject: [PATCH] Improve SessionManager constructor and tests Relates to https://github.com/shaarli/Shaarli/pull/1005 Changed: - pass a copy of the ConfigManager instance instead of a reference - move FakeConfigManager to a dedicated file - update tests Signed-off-by: VirtualTam --- application/SessionManager.php | 6 +++--- tests/SessionManagerTest.php | 31 ++++++++++--------------------- tests/utils/FakeConfigManager.php | 12 ++++++++++++ 3 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 tests/utils/FakeConfigManager.php diff --git a/application/SessionManager.php b/application/SessionManager.php index 3aa4ddfc..71f0b38d 100644 --- a/application/SessionManager.php +++ b/application/SessionManager.php @@ -12,12 +12,12 @@ class SessionManager * Constructor * * @param array $session The $_SESSION array (reference) - * @param ConfigManager $conf ConfigManager instance (reference) + * @param ConfigManager $conf ConfigManager instance */ - public function __construct(& $session, & $conf) + public function __construct(& $session, $conf) { $this->session = &$session; - $this->conf = &$conf; + $this->conf = $conf; } /** diff --git a/tests/SessionManagerTest.php b/tests/SessionManagerTest.php index a92c3ccc..aa75962a 100644 --- a/tests/SessionManagerTest.php +++ b/tests/SessionManagerTest.php @@ -1,4 +1,6 @@ generateToken(); @@ -61,9 +54,7 @@ class SessionManagerTest extends TestCase $token => 1, ], ]; - $conf = new FakeConfigManager(); - $sessionManager = new SessionManager($session, $conf); - + $sessionManager = new SessionManager($session, self::$conf); // check and destroy the token $this->assertTrue($sessionManager->checkToken($token)); @@ -79,8 +70,7 @@ class SessionManagerTest extends TestCase public function testGenerateAndCheckToken() { $session = []; - $conf = new FakeConfigManager(); - $sessionManager = new SessionManager($session, $conf); + $sessionManager = new SessionManager($session, self::$conf); $token = $sessionManager->generateToken(); @@ -102,8 +92,7 @@ class SessionManagerTest extends TestCase public function testCheckInvalidToken() { $session = []; - $conf = new FakeConfigManager(); - $sessionManager = new SessionManager($session, $conf); + $sessionManager = new SessionManager($session, self::$conf); $this->assertFalse($sessionManager->checkToken('4dccc3a45ad9d03e5542b90c37d8db6d10f2b38b')); } diff --git a/tests/utils/FakeConfigManager.php b/tests/utils/FakeConfigManager.php new file mode 100644 index 00000000..f29760cb --- /dev/null +++ b/tests/utils/FakeConfigManager.php @@ -0,0 +1,12 @@ +