|
2 | 2 | /** |
3 | 3 | * PHPUnit tests for models/Session/Handler.php |
4 | 4 | * |
| 5 | + * Test errors in PHPUnit 6.4.0 make sure to upgrade to 6.4.1 |
| 6 | + * |
5 | 7 | * @package php-simple-sessions |
6 | 8 | * @author Liam Kelly <https://github.com/likel> |
7 | 9 | * @copyright 2017 Liam Kelly |
|
14 | 16 | // Require the autoloader to load the models when required |
15 | 17 | require_once(__DIR__ . '/../src/autoload.php'); |
16 | 18 |
|
| 19 | +/** |
| 20 | + * @runTestsInSeparateProcesses |
| 21 | + */ |
17 | 22 | final class SessionHandlerTest extends TestCase |
18 | 23 | { |
| 24 | + private $session; |
| 25 | + |
| 26 | + /** |
| 27 | + * Destroy the session at the end of each test |
| 28 | + */ |
| 29 | + protected function tearDown() |
| 30 | + { |
| 31 | + if (session_status() == PHP_SESSION_ACTIVE) { |
| 32 | + session_destroy(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * No parameters supplied to constructor |
| 38 | + */ |
| 39 | + public function testConstructorNoParameters() |
| 40 | + { |
| 41 | + $this->session = new \Likel\Session\Handler(); |
| 42 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 43 | + } |
| 44 | + |
19 | 45 | /** |
20 | | - * Test for the constructor outcomes |
| 46 | + * Non-array parameter supplied to constructor |
21 | 47 | */ |
22 | | - public function testConstruct() |
| 48 | + public function testConstructorNonArray() |
23 | 49 | { |
| 50 | + $this->session = new \Likel\Session\Handler("a"); |
| 51 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 52 | + } |
24 | 53 |
|
| 54 | + /** |
| 55 | + * Supply a correct session_name parameter |
| 56 | + */ |
| 57 | + public function testConstructorSessionNameSet() |
| 58 | + { |
| 59 | + $this->session = new \Likel\Session\Handler(array( |
| 60 | + 'session_name' => "test_session" |
| 61 | + )); |
| 62 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 63 | + $this->assertEquals(session_name(), "test_session"); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Supply a correct secure parameter |
| 68 | + */ |
| 69 | + public function testConstructorSecureSet() |
| 70 | + { |
| 71 | + $this->session = new \Likel\Session\Handler(array( |
| 72 | + 'secure' => "true" |
| 73 | + )); |
| 74 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Supply a correct credentials_location parameter |
| 79 | + */ |
| 80 | + public function testConstructorCredentialsLocationSet() |
| 81 | + { |
| 82 | + $this->session = new \Likel\Session\Handler(array( |
| 83 | + 'credentials_location' => __DIR__ . '/../src/ini/credentials.ini' |
| 84 | + )); |
| 85 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Supply a parameter that doesn't exist |
| 90 | + */ |
| 91 | + public function testConstructorNonExistantParameter() |
| 92 | + { |
| 93 | + $this->session = new \Likel\Session\Handler(array( |
| 94 | + 'foo' => 'bar' |
| 95 | + )); |
| 96 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Incorrect secure parameter type supplied |
| 101 | + */ |
| 102 | + public function testConstructorIncorrectSecureType() |
| 103 | + { |
| 104 | + $this->session = new \Likel\Session\Handler(array( |
| 105 | + 'secure' => "false" |
| 106 | + )); |
| 107 | + $this->assertEquals(session_status(), PHP_SESSION_ACTIVE); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Incorrect credentials_location file path supplied |
| 112 | + */ |
| 113 | + public function testConstructorIncorrectCredentialsLocation() |
| 114 | + { |
| 115 | + $this->expectOutputString('The credential file could not be located.'); |
| 116 | + $this->session = new \Likel\Session\Handler(array( |
| 117 | + 'credentials_location' => "path" |
| 118 | + )); |
| 119 | + $this->assertEquals(session_status(), PHP_SESSION_NONE); |
25 | 120 | } |
26 | 121 | } |
0 commit comments