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