Skip to content

Commit bcb521e

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 cff5f29 + 9ccdf47 commit bcb521e

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

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());

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

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

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)