Skip to content

Commit 43c1f64

Browse files
committed
Add some tests to the handlers
1 parent dd65922 commit 43c1f64

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\NativeMemcachedSessionHandler;
16+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
17+
18+
/**
19+
* Test class for NativeMemcachedSessionHandler.
20+
*
21+
* @author Maurits van der Schee <maurits@vdschee.nl>
22+
*
23+
* @runTestsInSeparateProcesses
24+
* @preserveGlobalState disabled
25+
*/
26+
class NativeMemcachedSessionHandlerTest 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 NativeMemcachedSessionHandler($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('memcached.sess_locking'));
41+
}
42+
43+
public function savePathDataProvider()
44+
{
45+
return [
46+
['localhost:11211', ['name' => 'TESTING'], 'localhost:11211', 'TESTING'],
47+
['', ['name' => 'TESTING'], '', 'TESTING'],
48+
['', [], '', 'PHPSESSID'],
49+
];
50+
}
51+
52+
public function testConstructDefault()
53+
{
54+
ini_set('session.save_path', 'localhost:11211');
55+
ini_set('session.name', 'TESTING');
56+
57+
new NativeSessionStorage([], new NativeMemcachedSessionHandler());
58+
59+
$this->assertEquals('localhost:11211', ini_get('session.save_path'));
60+
$this->assertEquals('TESTING', ini_get('session.name'));
61+
$this->assertTrue((bool) ini_get('memcached.sess_locking'));
62+
}
63+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy