aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/SessionManagerTest.php31
-rw-r--r--tests/utils/FakeConfigManager.php12
2 files changed, 22 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 }
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 @@
1<?php
2
3/**
4 * Fake ConfigManager
5 */
6class FakeConfigManager
7{
8 public static function get($key)
9 {
10 return $key;
11 }
12}