a6264e51d2a72df84268d2a63ac5485f8f5f2bdb
[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         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
33         $this->assertEquals('user', ini_get('session.save_handler'));
34
35         $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
36         $this->assertEquals('TESTING', ini_get('session.name'));
37     }
38
39     /**
40      * @dataProvider savePathDataProvider
41      */
42     public function testConstructSavePath($savePath, $expectedSavePath, $path)
43     {
44         $handler = new NativeFileSessionHandler($savePath);
45         $this->assertEquals($expectedSavePath, ini_get('session.save_path'));
46         $this->assertTrue(is_dir(realpath($path)));
47
48         rmdir($path);
49     }
50
51     public function savePathDataProvider()
52     {
53         $base = sys_get_temp_dir();
54
55         return array(
56             array("$base/foo", "$base/foo", "$base/foo"),
57             array("5;$base/foo", "5;$base/foo", "$base/foo"),
58             array("5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"),
59         );
60     }
61
62     /**
63      * @expectedException \InvalidArgumentException
64      */
65     public function testConstructException()
66     {
67         $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
68     }
69
70     public function testConstructDefault()
71     {
72         $path = ini_get('session.save_path');
73         $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
74
75         $this->assertEquals($path, ini_get('session.save_path'));
76     }
77 }