aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SessionManagerTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam+github@flibidi.net>2017-11-24 23:53:15 +0100
committerGitHub <noreply@github.com>2017-11-24 23:53:15 +0100
commitd9514becc4d8b06e2a31c6975f3bbbaf6f1fed42 (patch)
tree301bed8a69d908c5b583a3c66cb36d1beac38271 /tests/SessionManagerTest.php
parent4e58d2edf79bb90b52e7235e4239b1e462bdd9aa (diff)
parentdd883aaf0999e9dc783a1a19bfeeab181c949d55 (diff)
downloadShaarli-d9514becc4d8b06e2a31c6975f3bbbaf6f1fed42.tar.gz
Shaarli-d9514becc4d8b06e2a31c6975f3bbbaf6f1fed42.tar.zst
Shaarli-d9514becc4d8b06e2a31c6975f3bbbaf6f1fed42.zip
Merge pull request #1016 from virtualtam/refactor/session
Improve SessionManager constructor and tests
Diffstat (limited to 'tests/SessionManagerTest.php')
-rw-r--r--tests/SessionManagerTest.php31
1 files changed, 10 insertions, 21 deletions
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 @@
1<?php 1<?php
2require_once 'tests/utils/FakeConfigManager.php';
3
2// Initialize reference data _before_ PHPUnit starts a session 4// Initialize reference data _before_ PHPUnit starts a session
3require_once 'tests/utils/ReferenceSessionIdHashes.php'; 5require_once 'tests/utils/ReferenceSessionIdHashes.php';
4ReferenceSessionIdHashes::genAllHashes(); 6ReferenceSessionIdHashes::genAllHashes();
@@ -8,18 +10,6 @@ use \PHPUnit\Framework\TestCase;
8 10
9 11
10/** 12/**
11 * Fake ConfigManager
12 */
13class FakeConfigManager
14{
15 public static function get($key)
16 {
17 return $key;
18 }
19}
20
21
22/**
23 * Test coverage for SessionManager 13 * Test coverage for SessionManager
24 */ 14 */
25class SessionManagerTest extends TestCase 15class SessionManagerTest extends TestCase
@@ -27,12 +17,16 @@ class SessionManagerTest extends TestCase
27 // Session ID hashes 17 // Session ID hashes
28 protected static $sidHashes = null; 18 protected static $sidHashes = null;
29 19
20 // Fake ConfigManager
21 protected static $conf = null;
22
30 /** 23 /**
31 * Assign reference data 24 * Assign reference data
32 */ 25 */
33 public static function setUpBeforeClass() 26 public static function setUpBeforeClass()
34 { 27 {
35 self::$sidHashes = ReferenceSessionIdHashes::getHashes(); 28 self::$sidHashes = ReferenceSessionIdHashes::getHashes();
29 self::$conf = new FakeConfigManager();
36 } 30 }
37 31
38 /** 32 /**
@@ -41,8 +35,7 @@ class SessionManagerTest extends TestCase
41 public function testGenerateToken() 35 public function testGenerateToken()
42 { 36 {
43 $session = []; 37 $session = [];
44 $conf = new FakeConfigManager(); 38 $sessionManager = new SessionManager($session, self::$conf);
45 $sessionManager = new SessionManager($session, $conf);
46 39
47 $token = $sessionManager->generateToken(); 40 $token = $sessionManager->generateToken();
48 41
@@ -61,9 +54,7 @@ class SessionManagerTest extends TestCase
61 $token => 1, 54 $token => 1,
62 ], 55 ],
63 ]; 56 ];
64 $conf = new FakeConfigManager(); 57 $sessionManager = new SessionManager($session, self::$conf);
65 $sessionManager = new SessionManager($session, $conf);
66
67 58
68 // check and destroy the token 59 // check and destroy the token
69 $this->assertTrue($sessionManager->checkToken($token)); 60 $this->assertTrue($sessionManager->checkToken($token));
@@ -79,8 +70,7 @@ class SessionManagerTest extends TestCase
79 public function testGenerateAndCheckToken() 70 public function testGenerateAndCheckToken()
80 { 71 {
81 $session = []; 72 $session = [];
82 $conf = new FakeConfigManager(); 73 $sessionManager = new SessionManager($session, self::$conf);
83 $sessionManager = new SessionManager($session, $conf);
84 74
85 $token = $sessionManager->generateToken(); 75 $token = $sessionManager->generateToken();
86 76
@@ -102,8 +92,7 @@ class SessionManagerTest extends TestCase
102 public function testCheckInvalidToken() 92 public function testCheckInvalidToken()
103 { 93 {
104 $session = []; 94 $session = [];
105 $conf = new FakeConfigManager(); 95 $sessionManager = new SessionManager($session, self::$conf);
106 $sessionManager = new SessionManager($session, $conf);
107 96
108 $this->assertFalse($sessionManager->checkToken('4dccc3a45ad9d03e5542b90c37d8db6d10f2b38b')); 97 $this->assertFalse($sessionManager->checkToken('4dccc3a45ad9d03e5542b90c37d8db6d10f2b38b'));
109 } 98 }