|
| 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\NativeRedisSessionHandler; |
| 16 | +use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; |
| 17 | + |
| 18 | +/** |
| 19 | + * Test class for NativeRedisSessionHandler. |
| 20 | + * |
| 21 | + * @author Maurits van der Schee <maurits@vdschee.nl> |
| 22 | + * |
| 23 | + * @runTestsInSeparateProcesses |
| 24 | + * @preserveGlobalState disabled |
| 25 | + */ |
| 26 | +class NativeRedisSessionHandlerTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @dataProvider savePathDataProvider |
| 30 | + */ |
| 31 | + public function testConstruct(string $savePath, array $sessionOptions, string $expectedSavePath, string $expectedSessionName) |
| 32 | + { |
| 33 | + ini_set('session.save_path', '/var/lib/php/sessions'); |
| 34 | + ini_set('session.name', 'PHPSESSID'); |
| 35 | + |
| 36 | + new NativeSessionStorage($sessionOptions, new NativeRedisSessionHandler($savePath, $sessionOptions)); |
| 37 | + |
| 38 | + $this->assertEquals($expectedSessionName, ini_get('session.name')); |
| 39 | + $this->assertEquals($expectedSavePath, ini_get('session.save_path')); |
| 40 | + $this->assertTrue((bool) ini_get('redis.session.locking_enabled')); |
| 41 | + } |
| 42 | + |
| 43 | + public function savePathDataProvider() |
| 44 | + { |
| 45 | + return [ |
| 46 | + ['tcp://localhost:6379', [], 'tcp://localhost:6379?prefix=PHPREDIS_SESSION.PHPSESSID.', 'PHPSESSID'], |
| 47 | + ['tcp://localhost:6379', ['name' => 'TESTING'], 'tcp://localhost:6379?prefix=PHPREDIS_SESSION.TESTING.', 'TESTING'], |
| 48 | + ['tcp://localhost:6379?prefix=CUSTOM.', ['name' => 'TESTING'], 'tcp://localhost:6379?prefix=CUSTOM.', 'TESTING'], |
| 49 | + ['tcp://localhost:6379?prefix=CUSTOM.&prefix=CUSTOM2.', ['name' => 'TESTING'], 'tcp://localhost:6379?prefix=CUSTOM2.', 'TESTING'], |
| 50 | + ]; |
| 51 | + } |
| 52 | + |
| 53 | + public function testConstructDefault() |
| 54 | + { |
| 55 | + ini_set('session.save_path', 'tcp://localhost:6379'); |
| 56 | + ini_set('session.name', 'TESTING'); |
| 57 | + |
| 58 | + new NativeSessionStorage([], new NativeRedisSessionHandler()); |
| 59 | + |
| 60 | + $this->assertEquals('tcp://localhost:6379?prefix=PHPREDIS_SESSION.TESTING.', ini_get('session.save_path')); |
| 61 | + $this->assertEquals('TESTING', ini_get('session.name')); |
| 62 | + $this->assertTrue((bool) ini_get('redis.session.locking_enabled')); |
| 63 | + } |
| 64 | +} |
0 commit comments