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
This commit is contained in:
commit
8b7c3d38b3
@ -15,6 +15,7 @@
|
|||||||
<env name="DUMP_STRING_LENGTH" value="" />
|
<env name="DUMP_STRING_LENGTH" value="" />
|
||||||
<env name="LDAP_HOST" value="127.0.0.1" />
|
<env name="LDAP_HOST" value="127.0.0.1" />
|
||||||
<env name="LDAP_PORT" value="3389" />
|
<env name="LDAP_PORT" value="3389" />
|
||||||
|
<env name="REDIS_HOST" value="localhost" />
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
@ -17,6 +17,16 @@ use Symfony\Component\Cache\Exception\InvalidArgumentException;
|
|||||||
|
|
||||||
class CachePoolsTest extends WebTestCase
|
class CachePoolsTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$_SERVER['SYMFONY__REDIS_HOST'] = getenv('REDIS_HOST');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
unset($_SERVER['SYMFONY__REDIS_HOST']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCachePools()
|
public function testCachePools()
|
||||||
{
|
{
|
||||||
$this->doTestCachePools(array(), FilesystemAdapter::class);
|
$this->doTestCachePools(array(), FilesystemAdapter::class);
|
||||||
@ -30,7 +40,7 @@ class CachePoolsTest extends WebTestCase
|
|||||||
try {
|
try {
|
||||||
$this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class);
|
$this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class);
|
||||||
} catch (\PHPUnit_Framework_Error_Warning $e) {
|
} catch (\PHPUnit_Framework_Error_Warning $e) {
|
||||||
if (0 !== strpos($e->getMessage(), 'unable to connect to 127.0.0.1')) {
|
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
$this->markTestSkipped($e->getMessage());
|
$this->markTestSkipped($e->getMessage());
|
||||||
@ -50,7 +60,7 @@ class CachePoolsTest extends WebTestCase
|
|||||||
try {
|
try {
|
||||||
$this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class);
|
$this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class);
|
||||||
} catch (\PHPUnit_Framework_Error_Warning $e) {
|
} catch (\PHPUnit_Framework_Error_Warning $e) {
|
||||||
if (0 !== strpos($e->getMessage(), 'unable to connect to 127.0.0.1')) {
|
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
$this->markTestSkipped($e->getMessage());
|
$this->markTestSkipped($e->getMessage());
|
||||||
|
@ -4,6 +4,7 @@ imports:
|
|||||||
framework:
|
framework:
|
||||||
cache:
|
cache:
|
||||||
app: cache.adapter.redis
|
app: cache.adapter.redis
|
||||||
|
default_redis_provider: "redis://%redis_host%"
|
||||||
pools:
|
pools:
|
||||||
cache.pool1:
|
cache.pool1:
|
||||||
public: true
|
public: true
|
||||||
|
@ -6,7 +6,7 @@ services:
|
|||||||
public: false
|
public: false
|
||||||
class: Redis
|
class: Redis
|
||||||
calls:
|
calls:
|
||||||
- [connect, [127.0.0.1]]
|
- [connect, ['%redis_host%']]
|
||||||
|
|
||||||
cache.app:
|
cache.app:
|
||||||
parent: cache.adapter.redis
|
parent: cache.adapter.redis
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
>
|
>
|
||||||
<php>
|
<php>
|
||||||
<ini name="error_reporting" value="-1" />
|
<ini name="error_reporting" value="-1" />
|
||||||
|
<env name="REDIS_HOST" value="localhost" />
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
@ -33,7 +33,7 @@ abstract class AbstractRedisAdapterTest extends AdapterTestCase
|
|||||||
if (!extension_loaded('redis')) {
|
if (!extension_loaded('redis')) {
|
||||||
self::markTestSkipped('Extension redis required.');
|
self::markTestSkipped('Extension redis required.');
|
||||||
}
|
}
|
||||||
if (!@((new \Redis())->connect('127.0.0.1'))) {
|
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
|
||||||
$e = error_get_last();
|
$e = error_get_last();
|
||||||
self::markTestSkipped($e['message']);
|
self::markTestSkipped($e['message']);
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,14 @@ class PredisAdapterTest extends AbstractRedisAdapterTest
|
|||||||
public static function setupBeforeClass()
|
public static function setupBeforeClass()
|
||||||
{
|
{
|
||||||
parent::setupBeforeClass();
|
parent::setupBeforeClass();
|
||||||
self::$redis = new \Predis\Client();
|
self::$redis = new \Predis\Client(array('host' => getenv('REDIS_HOST')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateConnection()
|
public function testCreateConnection()
|
||||||
{
|
{
|
||||||
$redis = RedisAdapter::createConnection('redis://localhost/1', array('class' => \Predis\Client::class, 'timeout' => 3));
|
$redisHost = getenv('REDIS_HOST');
|
||||||
|
|
||||||
|
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/1', array('class' => \Predis\Client::class, 'timeout' => 3));
|
||||||
$this->assertInstanceOf(\Predis\Client::class, $redis);
|
$this->assertInstanceOf(\Predis\Client::class, $redis);
|
||||||
|
|
||||||
$connection = $redis->getConnection();
|
$connection = $redis->getConnection();
|
||||||
@ -32,7 +34,7 @@ class PredisAdapterTest extends AbstractRedisAdapterTest
|
|||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'scheme' => 'tcp',
|
'scheme' => 'tcp',
|
||||||
'host' => 'localhost',
|
'host' => $redisHost,
|
||||||
'path' => '',
|
'path' => '',
|
||||||
'dbindex' => '1',
|
'dbindex' => '1',
|
||||||
'port' => 6379,
|
'port' => 6379,
|
||||||
|
@ -19,26 +19,28 @@ class RedisAdapterTest extends AbstractRedisAdapterTest
|
|||||||
{
|
{
|
||||||
parent::setupBeforeClass();
|
parent::setupBeforeClass();
|
||||||
self::$redis = new \Redis();
|
self::$redis = new \Redis();
|
||||||
self::$redis->connect('127.0.0.1');
|
self::$redis->connect(getenv('REDIS_HOST'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateConnection()
|
public function testCreateConnection()
|
||||||
{
|
{
|
||||||
$redis = RedisAdapter::createConnection('redis://localhost');
|
$redisHost = getenv('REDIS_HOST');
|
||||||
|
|
||||||
|
$redis = RedisAdapter::createConnection('redis://'.$redisHost);
|
||||||
$this->assertInstanceOf(\Redis::class, $redis);
|
$this->assertInstanceOf(\Redis::class, $redis);
|
||||||
$this->assertTrue($redis->isConnected());
|
$this->assertTrue($redis->isConnected());
|
||||||
$this->assertSame(0, $redis->getDbNum());
|
$this->assertSame(0, $redis->getDbNum());
|
||||||
|
|
||||||
$redis = RedisAdapter::createConnection('redis://localhost/2');
|
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'/2');
|
||||||
$this->assertSame(2, $redis->getDbNum());
|
$this->assertSame(2, $redis->getDbNum());
|
||||||
|
|
||||||
$redis = RedisAdapter::createConnection('redis://localhost', array('timeout' => 3));
|
$redis = RedisAdapter::createConnection('redis://'.$redisHost, array('timeout' => 3));
|
||||||
$this->assertEquals(3, $redis->getTimeout());
|
$this->assertEquals(3, $redis->getTimeout());
|
||||||
|
|
||||||
$redis = RedisAdapter::createConnection('redis://localhost?timeout=4');
|
$redis = RedisAdapter::createConnection('redis://'.$redisHost.'?timeout=4');
|
||||||
$this->assertEquals(4, $redis->getTimeout());
|
$this->assertEquals(4, $redis->getTimeout());
|
||||||
|
|
||||||
$redis = RedisAdapter::createConnection('redis://localhost', array('read_timeout' => 5));
|
$redis = RedisAdapter::createConnection('redis://'.$redisHost, array('read_timeout' => 5));
|
||||||
$this->assertEquals(5, $redis->getReadTimeout());
|
$this->assertEquals(5, $redis->getReadTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,6 @@ class RedisArrayAdapterTest extends AbstractRedisAdapterTest
|
|||||||
if (!class_exists('RedisArray')) {
|
if (!class_exists('RedisArray')) {
|
||||||
self::markTestSkipped('The RedisArray class is required.');
|
self::markTestSkipped('The RedisArray class is required.');
|
||||||
}
|
}
|
||||||
self::$redis = new \RedisArray(array('localhost'), array('lazy_connect' => true));
|
self::$redis = new \RedisArray(array(getenv('REDIS_HOST')), array('lazy_connect' => true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
>
|
>
|
||||||
<php>
|
<php>
|
||||||
<ini name="error_reporting" value="-1" />
|
<ini name="error_reporting" value="-1" />
|
||||||
|
<env name="REDIS_HOST" value="localhost" />
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
Reference in New Issue
Block a user