Skip to content

Commit

Permalink
[5.3] Fail-safing Queue's Predis/Redis Unit Tests & Move to phpunit.x…
Browse files Browse the repository at this point in the history
…ml.dist (laravel#14696)

* Refactored testing setup:
- renamed phpunit.xml to phpunit.xml.dist (supported by phpunit)
- added phpunit.xml to the .gitignore
- added commented out redis configuration
- Redis based tests are skipped when configuration not present

* - Added default parameter/connection checking to Queue's Redis integration tests
- Failsafe skipping for default connection
- Added connection timeout of .5s for Predis

* Style fixes
  • Loading branch information
ralphschindler authored and tillkruss committed Aug 30, 2016
1 parent bd57f57 commit bfca5c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
.php_cs.cache
.DS_Store
Thumbs.db
/phpunit.xml
6 changes: 6 additions & 0 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
</exclude>
</whitelist>
</filter>
<php>
<!--
<env name="REDIS_HOST" value="127.0.0.1" />
<env name="REDIS_PORT" value="6379" />
-->
</php>
</phpunit>
36 changes: 32 additions & 4 deletions tests/Queue/RedisQueueIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class RedisQueueIntegrationTest extends PHPUnit_Framework_TestCase
{
/**
* @var bool
*/
private static $connectionFailedOnceWithDefaultsSkip = false;

/**
* @var Database
*/
Expand All @@ -21,15 +26,36 @@ class RedisQueueIntegrationTest extends PHPUnit_Framework_TestCase
public function setUp()
{
parent::setUp();

$host = getenv('REDIS_HOST') ?: '127.0.0.1';
$port = getenv('REDIS_PORT') ?: 6379;

if (static::$connectionFailedOnceWithDefaultsSkip) {
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);

return;
}

$this->redis = new Database([
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'host' => $host,
'port' => $port,
'database' => 5,
'timeout' => 0.5,
],
]);
$this->redis->connection()->flushdb();

try {
$this->redis->connection()->flushdb();
} catch (\Exception $e) {
if ($host === '127.0.0.1' && $port === 6379 && getenv('REDIS_HOST') === false) {
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
static::$connectionFailedOnceWithDefaultsSkip = true;

return;
}
}

$this->queue = new RedisQueue($this->redis);
$this->queue->setContainer(m::mock(Container::class));
Expand All @@ -39,7 +65,9 @@ public function tearDown()
{
parent::tearDown();
m::close();
$this->redis->connection()->flushdb();
if ($this->redis) {
$this->redis->connection()->flushdb();
}
}

public function testExpiredJobsArePopped()
Expand Down

0 comments on commit bfca5c9

Please sign in to comment.