4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
16 use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
19 * Test class for NativeFileSessionHandler.
21 * @author Drak <drak@zikula.org>
23 * @runTestsInSeparateProcesses
24 * @preserveGlobalState disabled
26 class NativeFileSessionHandlerTest extends TestCase
28 public function testConstruct()
30 $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
32 if (\PHP_VERSION_ID < 50400) {
33 $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
34 $this->assertEquals('files', ini_get('session.save_handler'));
36 $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
37 $this->assertEquals('user', ini_get('session.save_handler'));
40 $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
41 $this->assertEquals('TESTING', ini_get('session.name'));
45 * @dataProvider savePathDataProvider
47 public function testConstructSavePath($savePath, $expectedSavePath, $path)
49 $handler = new NativeFileSessionHandler($savePath);
50 $this->assertEquals($expectedSavePath, ini_get('session.save_path'));
51 $this->assertTrue(is_dir(realpath($path)));
56 public function savePathDataProvider()
58 $base = sys_get_temp_dir();
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"),
68 * @expectedException \InvalidArgumentException
70 public function testConstructException()
72 $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
75 public function testConstructDefault()
77 $path = ini_get('session.save_path');
78 $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
80 $this->assertEquals($path, ini_get('session.save_path'));