Yaffs site version 1.1
[yaffs-website] / vendor / symfony / http-foundation / Tests / Session / Storage / Handler / NativeFileSessionHandlerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
16 use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
17
18 /**
19  * Test class for NativeFileSessionHandler.
20  *
21  * @author Drak <drak@zikula.org>
22  *
23  * @runTestsInSeparateProcesses
24  * @preserveGlobalState disabled
25  */
26 class NativeFileSessionHandlerTest extends TestCase
27 {
28     public function testConstruct()
29     {
30         $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
31
32         if (\PHP_VERSION_ID < 50400) {
33             $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
34             $this->assertEquals('files', ini_get('session.save_handler'));
35         } else {
36             $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
37             $this->assertEquals('user', ini_get('session.save_handler'));
38         }
39
40         $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
41         $this->assertEquals('TESTING', ini_get('session.name'));
42     }
43
44     /**
45      * @dataProvider savePathDataProvider
46      */
47     public function testConstructSavePath($savePath, $expectedSavePath, $path)
48     {
49         $handler = new NativeFileSessionHandler($savePath);
50         $this->assertEquals($expectedSavePath, ini_get('session.save_path'));
51         $this->assertTrue(is_dir(realpath($path)));
52
53         rmdir($path);
54     }
55
56     public function savePathDataProvider()
57     {
58         $base = sys_get_temp_dir();
59
60         return array(
61             array("$base/foo", "$base/foo", "$base/foo"),
62             array("5;$base/foo", "5;$base/foo", "$base/foo"),
63             array("5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"),
64         );
65     }
66
67     /**
68      * @expectedException \InvalidArgumentException
69      */
70     public function testConstructException()
71     {
72         $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
73     }
74
75     public function testConstructDefault()
76     {
77         $path = ini_get('session.save_path');
78         $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
79
80         $this->assertEquals($path, ini_get('session.save_path'));
81     }
82 }