1212 */
1313class FileEncryptionTest extends TestCase
1414{
15- public static function setUpBeforeClass ()
15+ private function getPath ()
1616 {
17- if (file_exists (__DIR__ . '/toto ' )) {
18- rmdir (__DIR__ . '/toto ' );
17+ $ path = ini_get ('session.save_path ' );
18+ if (empty ($ path )) {
19+ return DIRECTORY_SEPARATOR . 'tmp ' ;
1920 }
21+
22+ return $ path ;
2023 }
2124
22- public static function setUpAfterClass ( )
25+ private function openSessionForSavingSavePath ( FileEncryption $ fileEncryption )
2326 {
24- if (file_exists (__DIR__ . '/toto ' )) {
25- rmdir (__DIR__ . '/toto ' );
26- }
27+ $ success = $ fileEncryption ->open ($ this ->getPath (), '' );
28+ static ::assertTrue ($ success );
2729 }
2830
2931 public function testOpen ()
3032 {
3133 $ fileEncryption = new FileEncryption ();
3234 $ fileEncryption ->setKey ('randomKey ' );
33- $ savePath = __DIR__ ;
35+
36+ $ savePath = $ this ->getPath ();
3437 $ sessionName = '' ;
3538 $ success = $ fileEncryption ->open ($ savePath , $ sessionName );
3639 static ::assertTrue ($ success );
3740
38- $ success = $ fileEncryption ->open ($ savePath . '/toto ' , $ sessionName );
41+ $ success = $ fileEncryption ->open ($ savePath . '/tests ' , $ sessionName );
3942 static ::assertTrue ($ success );
40- $ success = file_exists ($ savePath . '/toto ' );
43+ $ success = file_exists ($ savePath . '/tests ' );
4144 static ::assertTrue ($ success );
4245 }
4346
@@ -53,6 +56,9 @@ public function testWrite()
5356 {
5457 $ fileEncryption = new FileEncryption ();
5558 $ fileEncryption ->setKey ('randomKey ' );
59+
60+ $ this ->openSessionForSavingSavePath ($ fileEncryption );
61+
5662 $ sessionId = 'test ' ;
5763 $ data = 'azerty ' ;
5864 $ success = $ fileEncryption ->write ($ sessionId , $ data );
@@ -63,6 +69,9 @@ public function testRead()
6369 {
6470 $ fileEncryption = new FileEncryption ();
6571 $ fileEncryption ->setKey ('randomKey ' );
72+
73+ $ this ->openSessionForSavingSavePath ($ fileEncryption );
74+
6675 $ sessionId = 'test ' ;
6776 $ data = $ fileEncryption ->read ($ sessionId );
6877 static ::assertTrue (!empty ($ data ));
@@ -78,13 +87,19 @@ public function testDestroy()
7887 {
7988 $ fileEncryption = new FileEncryption ();
8089 $ fileEncryption ->setKey ('randomKey ' );
90+
91+ $ this ->openSessionForSavingSavePath ($ fileEncryption );
92+
8193 $ sessionId = 'todelete ' ;
8294 $ data = '' ;
8395 $ success = $ fileEncryption ->write ($ sessionId , $ data );
8496 static ::assertTrue ($ success );
8597
8698 $ fileEncryption = new FileEncryption ();
8799 $ fileEncryption ->setKey ('randomKey ' );
100+
101+ $ this ->openSessionForSavingSavePath ($ fileEncryption );
102+
88103 $ sessionId = 'todelete ' ;
89104 $ fileEncryption ->destroy ($ sessionId );
90105 static ::assertTrue (true );
@@ -94,6 +109,9 @@ public function testGc()
94109 {
95110 $ fileEncryption = new FileEncryption ();
96111 $ fileEncryption ->setKey ('randomKey ' );
112+
113+ $ this ->openSessionForSavingSavePath ($ fileEncryption );
114+
97115 $ lifetime = -1000 ;
98116 $ fileEncryption ->gc ($ lifetime );
99117 static ::assertTrue (true );
0 commit comments