|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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\SessionHandlerFactory; |
| 16 | +use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler; |
| 17 | + |
| 18 | +/** |
| 19 | + * Test class for SessionHandlerFactory. |
| 20 | + * |
| 21 | + * @author Simon <[email protected]> |
| 22 | + * |
| 23 | + * @runTestsInSeparateProcesses |
| 24 | + * @preserveGlobalState disabled |
| 25 | + */ |
| 26 | +class SessionHandlerFactoryTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @dataProvider provideConnectionDSN |
| 30 | + */ |
| 31 | + public function testCreateHandler(string $connectionDSN, string $expectedPath, string $expectedHandlerType) |
| 32 | + { |
| 33 | + $handler = SessionHandlerFactory::createHandler($connectionDSN); |
| 34 | + |
| 35 | + $this->assertInstanceOf($expectedHandlerType, $handler); |
| 36 | + $this->assertEquals($expectedPath, ini_get('session.save_path')); |
| 37 | + } |
| 38 | + |
| 39 | + public function provideConnectionDSN(): array |
| 40 | + { |
| 41 | + $base = sys_get_temp_dir(); |
| 42 | + |
| 43 | + return [ |
| 44 | + 'native file handler using save_path from php.ini' => ['connectionDSN' => 'file://', 'expectedPath' => ini_get('session.save_path'), 'expectedHandlerType' => StrictSessionHandler::class], |
| 45 | + 'native file handler using provided save_path' => ['connectionDSN' => 'file://'.$base.'/session/storage', 'expectedPath' => $base.'/session/storage', 'expectedHandlerType' => StrictSessionHandler::class], |
| 46 | + ]; |
| 47 | + } |
| 48 | +} |
0 commit comments