Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff1727e

Browse files
Merge branch '4.1'
* 4.1: [HttpFoundation] cleanup test case [HttpFoundation] Allow RedisCluster class for RedisSessionHandler
2 parents9ef362e +620dfde commitff1727e

File tree

5 files changed

+53
-48
lines changed

5 files changed

+53
-48
lines changed

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ public function registerAliasForArgument(string $id, string $type, string $name
13501350
$name =lcfirst(str_replace('','',ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/','',$name ??$id))));
13511351

13521352
if (!preg_match('/^[a-zA-Z_\x7f-\xff]/',$name)) {
1353-
thrownew\InvalidArgumentException(sprintf('Invalid argument name "%s" for service "%s": the first character must be a letter.',$name,$id));
1353+
thrownewInvalidArgumentException(sprintf('Invalid argument name "%s" for service "%s": the first character must be a letter.',$name,$id));
13541354
}
13551355

13561356
return$this->setAlias($type.' $'.$name,$id);

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ class RedisSessionHandler extends AbstractSessionHandler
3333
* List of available options:
3434
* * prefix: The prefix to use for the keys in order to avoid collision on the Redis server.
3535
*
36-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redis
37-
* @param array $options An associative array of options
36+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client|RedisProxy $redis
37+
* @param array$options An associative array of options
3838
*
3939
* @throws \InvalidArgumentException When unsupported client or options are passed
4040
*/
4141
publicfunction__construct($redis,array$options =array())
4242
{
43-
if (!$redisinstanceof \Redis && !$redisinstanceof \RedisArray && !$redisinstanceof \Predis\Client && !$redisinstanceof RedisProxy) {
43+
if (
44+
!$redisinstanceof \Redis &&
45+
!$redisinstanceof \RedisArray &&
46+
!$redisinstanceof \RedisCluster &&
47+
!$redisinstanceof \Predis\Client &&
48+
!$redisinstanceof RedisProxy
49+
) {
4450
thrownew \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\Client, %s given',__METHOD__,\is_object($redis) ?\get_class($redis) :\gettype($redis)));
4551
}
4652

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php‎

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
3232
*/
3333
protected$redisClient;
3434

35-
/**
36-
* @var \Redis
37-
*/
38-
protected$validator;
39-
4035
/**
4136
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
4237
*/
@@ -52,9 +47,6 @@ protected function setUp()
5247

5348
$host =getenv('REDIS_HOST') ?:'localhost';
5449

55-
$this->validator =new \Redis();
56-
$this->validator->connect($host);
57-
5850
$this->redisClient =$this->createRedisClient($host);
5951
$this->storage =newRedisSessionHandler(
6052
$this->redisClient,
@@ -82,8 +74,8 @@ public function testCloseSession()
8274

8375
publicfunctiontestReadSession()
8476
{
85-
$this->setFixture(self::PREFIX.'id1',null);
86-
$this->setFixture(self::PREFIX.'id2','abc123');
77+
$this->redisClient->set(self::PREFIX.'id1',null);
78+
$this->redisClient->set(self::PREFIX.'id2','abc123');
8779

8880
$this->assertEquals('',$this->storage->read('id1'));
8981
$this->assertEquals('abc123',$this->storage->read('id2'));
@@ -93,26 +85,26 @@ public function testWriteSession()
9385
{
9486
$this->assertTrue($this->storage->write('id','data'));
9587

96-
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
97-
$this->assertEquals('data',$this->getFixture(self::PREFIX.'id'));
88+
$this->assertTrue((bool)$this->redisClient->exists(self::PREFIX.'id'));
89+
$this->assertEquals('data',$this->redisClient->get(self::PREFIX.'id'));
9890
}
9991

10092
publicfunctiontestUseSessionGcMaxLifetimeAsTimeToLive()
10193
{
10294
$this->storage->write('id','data');
103-
$ttl =$this->fixtureTtl(self::PREFIX.'id');
95+
$ttl =$this->redisClient->ttl(self::PREFIX.'id');
10496

10597
$this->assertLessThanOrEqual(ini_get('session.gc_maxlifetime'),$ttl);
10698
$this->assertGreaterThanOrEqual(0,$ttl);
10799
}
108100

109101
publicfunctiontestDestroySession()
110102
{
111-
$this->setFixture(self::PREFIX.'id','foo');
103+
$this->redisClient->set(self::PREFIX.'id','foo');
112104

113-
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
105+
$this->assertTrue((bool)$this->redisClient->exists(self::PREFIX.'id'));
114106
$this->assertTrue($this->storage->destroy('id'));
115-
$this->assertFalse($this->hasFixture(self::PREFIX.'id'));
107+
$this->assertFalse((bool)$this->redisClient->exists(self::PREFIX.'id'));
116108
}
117109

118110
publicfunctiontestGcSession()
@@ -122,12 +114,12 @@ public function testGcSession()
122114

123115
publicfunctiontestUpdateTimestamp()
124116
{
125-
$lowTTL =10;
117+
$lowTtl =10;
126118

127-
$this->setFixture(self::PREFIX.'id','foo',$lowTTL);
119+
$this->redisClient->setex(self::PREFIX.'id',$lowTtl,'foo');
128120
$this->storage->updateTimestamp('id',array());
129121

130-
$this->assertGreaterThan($lowTTL,$this->fixtureTtl(self::PREFIX.'id'));
122+
$this->assertGreaterThan($lowTtl,$this->redisClient->ttl(self::PREFIX.'id'));
131123
}
132124

133125
/**
@@ -150,28 +142,4 @@ public function getOptionFixtures(): array
150142
array(array('prefix' =>'sfs','foo' =>'bar'),false),
151143
);
152144
}
153-
154-
protectedfunctionsetFixture($key,$value,$ttl =null)
155-
{
156-
if (null !==$ttl) {
157-
$this->validator->setex($key,$ttl,$value);
158-
}else {
159-
$this->validator->set($key,$value);
160-
}
161-
}
162-
163-
protectedfunctiongetFixture($key)
164-
{
165-
return$this->validator->get($key);
166-
}
167-
168-
protectedfunctionhasFixture($key):bool
169-
{
170-
return$this->validator->exists($key);
171-
}
172-
173-
protectedfunctionfixtureTtl($key):int
174-
{
175-
return$this->validator->ttl($key);
176-
}
177145
}

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCas
1717
{
1818
protectedfunctioncreateRedisClient(string$host):Client
1919
{
20-
returnnewClient(array(array('host' =>$host)));
20+
returnnewClient(array(array('host' =>$host)));
2121
}
2222
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
namespaceSymfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
13+
14+
class RedisClusterSessionHandlerTestextends AbstractRedisSessionHandlerTestCase
15+
{
16+
publicstaticfunctionsetupBeforeClass()
17+
{
18+
if (!class_exists('RedisCluster')) {
19+
self::markTestSkipped('The RedisCluster class is required.');
20+
}
21+
22+
if (!$hosts =getenv('REDIS_CLUSTER_HOSTS')) {
23+
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
24+
}
25+
}
26+
27+
protectedfunctioncreateRedisClient(string$host):\RedisCluster
28+
{
29+
returnnew \RedisCluster(null,explode('',getenv('REDIS_CLUSTER_HOSTS')));
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp