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 $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
33 $this->assertEquals('user', ini_get('session.save_handler'));
35 $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
36 $this->assertEquals('TESTING', ini_get('session.name'));
40 * @dataProvider savePathDataProvider
42 public function testConstructSavePath($savePath, $expectedSavePath, $path)
44 $handler = new NativeFileSessionHandler($savePath);
45 $this->assertEquals($expectedSavePath, ini_get('session.save_path'));
46 $this->assertTrue(is_dir(realpath($path)));
51 public function savePathDataProvider()
53 $base = sys_get_temp_dir();
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"),
63 * @expectedException \InvalidArgumentException
65 public function testConstructException()
67 $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
70 public function testConstructDefault()
72 $path = ini_get('session.save_path');
73 $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
75 $this->assertEquals($path, ini_get('session.save_path'));