2010-04-18 13:58:43 +00:00
|
|
|
<?php
|
2021-02-18 23:23:32 +00:00
|
|
|
|
|
|
|
namespace Resque\Test;
|
|
|
|
|
2010-04-18 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Resque test bootstrap file - sets up a test environment.
|
|
|
|
*
|
2018-05-25 07:26:54 +00:00
|
|
|
* @package Resque/Tests
|
2019-06-02 10:21:42 +00:00
|
|
|
* @author Daniel Mason <daniel@m2.nz>
|
2018-05-25 07:26:54 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
2010-04-18 13:58:43 +00:00
|
|
|
*/
|
|
|
|
|
2013-01-12 11:01:13 +00:00
|
|
|
$loader = require __DIR__ . '/../vendor/autoload.php';
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2019-06-02 10:21:42 +00:00
|
|
|
# Redis configuration
|
|
|
|
global $redisTestServer;
|
2019-06-02 11:01:52 +00:00
|
|
|
$redisTestServer = getenv("REDIS_SERVER") ?: "redis";
|
2021-02-18 23:23:32 +00:00
|
|
|
\Resque\Resque::setBackend($redisTestServer);
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2019-06-02 10:21:42 +00:00
|
|
|
# Check Redis is accessable locally
|
|
|
|
try {
|
2021-02-18 23:23:32 +00:00
|
|
|
$redisTest = new \Resque\Redis($redisTestServer);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
throw new \Exception("Unable to connect to redis. Please check there is a redis-server running.");
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
2019-06-02 10:21:42 +00:00
|
|
|
$redisTest = null;
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2019-06-02 10:21:42 +00:00
|
|
|
# Cleanup forked workers cleanly
|
2018-05-25 07:26:54 +00:00
|
|
|
if (function_exists('pcntl_signal')) {
|
2021-02-18 23:23:32 +00:00
|
|
|
pcntl_signal(SIGINT, function() { exit; });
|
|
|
|
pcntl_signal(SIGTERM, function() { exit; });
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 10:21:42 +00:00
|
|
|
# Bootstrap it
|
2021-02-18 23:23:32 +00:00
|
|
|
class TestJob
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
2018-05-25 07:26:54 +00:00
|
|
|
public static $called = false;
|
2011-03-27 07:42:46 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function perform()
|
|
|
|
{
|
|
|
|
self::$called = true;
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
class FailingJobException extends \Exception
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
class FailingJob
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
2018-05-25 07:26:54 +00:00
|
|
|
public function perform()
|
|
|
|
{
|
2021-02-18 23:23:32 +00:00
|
|
|
throw new FailingJobException('Message!');
|
2018-05-25 07:26:54 +00:00
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
class TestJobWithoutPerformMethod
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
2010-04-20 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
class TestJobWithSetUp
|
2010-04-20 00:02:34 +00:00
|
|
|
{
|
2018-05-25 07:26:54 +00:00
|
|
|
public static $called = false;
|
|
|
|
public $args = false;
|
2010-04-20 00:02:34 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
self::$called = true;
|
|
|
|
}
|
2010-04-20 00:02:34 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function perform()
|
|
|
|
{
|
|
|
|
}
|
2010-04-20 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-18 23:23:32 +00:00
|
|
|
class TestJobWithTearDown
|
2010-04-20 00:02:34 +00:00
|
|
|
{
|
2018-05-25 07:26:54 +00:00
|
|
|
public static $called = false;
|
|
|
|
public $args = false;
|
2010-04-20 00:02:34 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function perform()
|
|
|
|
{
|
|
|
|
}
|
2010-04-20 00:02:34 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
self::$called = true;
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|