8000 [HttpFoundation] fix SessionHandlerFactory using connections by dmaicher · Pull Request #44378 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] fix SessionHandlerFactory using connections #44378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function createHandler($connection): AbstractSessionHandler
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, get_debug_type($connection)));
}

if ($options = parse_url($connection)) {
if ($options = \is_string($connection) ? parse_url($connection) : false) {
parse_str($options['query'] ?? '', $options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;

Expand All @@ -28,7 +29,7 @@ class SessionHandlerFactoryTest extends TestCase
/**
* @dataProvider provideConnectionDSN
*/
public function testCreateHandler(string $connectionDSN, string $expectedPath, string $expectedHandlerType)
public function testCreateFileHandler(string $connectionDSN, string $expectedPath, string $expectedHandlerType)
{
$handler = SessionHandlerFactory::createHandler($connectionDSN);

Expand All @@ -45,4 +46,32 @@ public function provideConnectionDSN(): array
'native file handler using provided save_path' => ['connectionDSN' => 'file://'.$base.'/session/storage', 'expectedPath' => $base.'/session/storage', 'expectedHandlerType' => StrictSessionHandler::class],
];
}

/**
* @requires extension redis
*/
public function testCreateRedisHandlerFromConnectionObject()
{
$handler = SessionHandlerFactory::createHandler($this->createMock(\Redis::class));
$this->assertInstanceOf(RedisSessionHandler::class, $handler);
}

/**
* @requires extension redis
*/
public function testCreateRedisHandlerFromDsn()
{
$handler = SessionHandlerFactory::createHandler('redis://localhost?prefix=foo&ttl=3600&ignored=bar');
$this->assertInstanceOf(RedisSessionHandler::class, $handler);

$reflection = new \ReflectionObject($handler);

$prefixProperty = $reflection->getProperty('prefix');
$prefixProperty->setAccessible(true);
$this->assertSame('foo', $prefixProperty->getValue($handler));

$ttlProperty = $reflection->getProperty('ttl');
$ttlProperty->setAccessible(true);
$this->assertSame('3600', $ttlProperty->getValue($handler));
}
}
0