8000 minor #19974 Make redis host configurable in tests (jakzal) · symfony/symfony@8b7c3d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b7c3d3

Browse files
committed
minor #19974 Make redis host configurable in tests (jakzal)
This PR was squashed before being merged into the 3.1 branch (closes #19974). Discussion ---------- Make redis host configurable in tests | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Makes running tests on dockerized environments possible, since we can now export the `REDIS_HOST` environment variable: ``` REDIS_HOST=redis ./phpunit src/Symfony/Component/Cache ``` If this gets merged, in master we can later replace the `SYMFONY__REDIS_HOST` usage in the FrameworkBundle with the new `env(REDIS_HOST)`. Commits ------- c87de00 Make redis host configurable in tests
2 parents ad7bc03 + c87de00 commit 8b7c3d3

File tree

10 files changed

+32
-14
lines changed

10 files changed

+32
-14
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<env name="DUMP_STRING_LENGTH" value="" />
1616
<env name="LDAP_HOST" value="127.0.0.1" />
1717
<env name="LDAP_PORT" value="3389" />
18+
<env name="REDIS_HOST" value="localhost" />
1819
</php>
1920

2021
<testsuites>

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717

1818
class CachePoolsTest extends WebTestCase
1919
{
20+
protected function setUp()
21+
{
22+
$_SERVER['SYMFONY__REDIS_HOST'] = getenv('REDIS_HOST');
23+
}
24+
25+
protected function tearDown()
26+
{
27+
unset($_SERVER['SYMFONY__REDIS_HOST']);
28+
}
29+
2030
public function testCachePools()
2131
{
2232
$this->doTestCachePools(array(), FilesystemAdapter::class);
@@ -30,7 +40,7 @@ public function testRedisCachePools()
3040
try {
3141
$this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class);
3242
} catch (\PHPUnit_Framework_Error_Warning $e) {
33-
if (0 !== strpos($e->getMessage(), 'unable to connect to 127.0.0.1')) {
43+
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
3444
throw $e;
3545
}
3646
$this->markTestSkipped($e->getMessage());
@@ -50,7 +60,7 @@ public function testRedisCustomCachePools()
5060
try {
5161
$this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class);
5262
} catch (\PHPUnit_Framework_Error_Warning $e) {
53-
if (0 !== strpos($e->getMessage(), 'unable to connect to 127.0.0.1')) {
63+
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
5464
throw $e;
5565
}
5666
$this->markTestSkipped($e->getMessage());

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ imports:
44
framework:
55
cache:
66
app: cache.adapter.redis
7+
default_redis_provider: "redis://%redis_host%"
78
pools:
89
cache.pool1:
910
public: true

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/redis_custom_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
public: false
77
class: Redis
88
calls:
9-
- [connect, [127.0.0.1]]
9+
- [connect, ['%redis_host%']]
1010

1111
cache.app:
1212
parent: cache.adapter.redis

src/Symfony/Bundle/FrameworkBundle/phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
>
99
<php>
1010
<ini name="error_reporting" value="-1" />
11+
<env name="REDIS_HOST" value="localhost" />
1112
</php>
1213

1314
<testsuites>

src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function setupBeforeClass()
3333
if (!extension_loaded('redis')) {
3434
self::markTestSkipped('Extension redis required.');
3535
}
36-
if (!@((new \Redis())->connect('127.0.0.1'))) {
36+
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
3737
$e = error_get_last();
3838
self::markTestSkipped($e['message']);
3939
}

src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ class PredisAdapterTest extends AbstractRedisAdapterTest
1919
public static function setupBeforeClass()
2020
{
2121
parent::setupBeforeClass();
22-
self::$redis = new \Predis\Client();
22+
self::$redis = new \Predis\Client(array('host' => getenv('REDIS_HOST')));
2323
}
2424

2525
public function testCreateConnection()
2626
{
27-
$redis = RedisAdapter::createConnection('redis://localhost/1', array('class' => \Predis\Client::class, 'timeout' => 3));
27+
$redisHost = getenv('REDIS_HOST');
28+
29+
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/1', array('class' => \Predis\Client::class, 'timeout' => 3));
2830
$this->assertInstanceOf(\Predis\Client::class, $redis);
2931

3032
$connection = $redis->getConnection();
3133
$this->assertInstanceOf(StreamConnection::class, $connection);
3234

3335
$params = array(
3436
'scheme' => 'tcp',
35-
'host' => 'localhost',
37+
'host' => $redisHost,
3638
'path' => '',
3739
'dbindex' => '1',
3840
'port' => 6379,

src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,28 @@ public static function setupBeforeClass()
1919
{
2020
parent::setupBeforeClass();
2121
self::$redis = new \Redis();
22-
self::$redis->connect('127.0.0.1');
22+
self::$redis->connect(getenv('REDIS_HOST'));
2323
}
2424

2525
public function testCreateConnection()
2626
{
27-
$redis = RedisAdapter::createConnection('redis://localhost');
27+
$redisHost = getenv('REDIS_HOST');
28+
29+
$redis = RedisAdapter::createConnection('redis://'.$redisHost);
2830
$this->assertInstanceOf(\Redis::class, $redis);
2931
$this->assertTrue($redis->isConnected());
3032
$this->assertSame(0, $redis->getDbNum());
3133

32-
$redis = RedisAdapter::createConnection('redis://localhost/2');
34+
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/2');
3335
$this->assertSame(2, $redis->getDbNum());
3436

35-
$redis = RedisAdapter::createConnection('redis://localhost', array('timeout' => 3));
37+
$redis = RedisAdapter::createConnection('redis://'.$redisHost, array('timeout' => 3));
3638
$this->assertEquals(3, $redis->getTimeout());
3739

38-
$redis = RedisAdapter::createConnection('redis://localhost?timeout=4');
40+
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'?timeout=4');
3941
$this->assertEquals(4, $redis->getTimeout());
4042

41-
$redis = RedisAdapter::createConnection('redis://localhost', array('read_timeout' => 5));
43+
$redis = RedisAdapter::createConnection('redis://'.$redisHost, array('read_timeout' => 5));
4244
$this->assertEquals(5, $redis->getReadTimeout());
4345
}
4446

src/Symfony/Component/Cache/Tests/Adapter/RedisArrayAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public static function setupBeforeClass()
1919
if (!class_exists('RedisArray')) {
2020
self::markTestSkipped('The RedisArray class is required.');
2121
}
22-
self::$redis = new \RedisArray(array('localhost'), array('lazy_connect' => true));
22+
self::$redis = new \RedisArray(array(getenv('REDIS_HOST')), array('lazy_connect' => true));
2323
}
2424
}

src/Symfony/Component/Cache/phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
>
99
<php>
1010
<ini name="error_reporting" value="-1" />
11+
<env name="REDIS_HOST" value="localhost" />
1112
</php>
1213

1314
<testsuites>

0 commit comments

Comments
 (0)
0