2010-04-18 13:58:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
$loader->add('Resque_Tests', __DIR__);
|
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";
|
2019-06-02 10:21:42 +00:00
|
|
|
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 {
|
|
|
|
$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')) {
|
|
|
|
function sigint()
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
pcntl_signal(SIGINT, 'sigint');
|
|
|
|
pcntl_signal(SIGTERM, 'sigint');
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 10:21:42 +00:00
|
|
|
# Bootstrap it
|
2010-04-18 13:58:43 +00:00
|
|
|
class Test_Job
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
class Failing_Job_Exception extends Exception
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Failing_Job
|
|
|
|
{
|
2018-05-25 07:26:54 +00:00
|
|
|
public function perform()
|
|
|
|
{
|
|
|
|
throw new Failing_Job_Exception('Message!');
|
|
|
|
}
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Test_Job_Without_Perform_Method
|
|
|
|
{
|
|
|
|
|
2010-04-20 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Test_Job_With_SetUp
|
|
|
|
{
|
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
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
}
|
2010-04-20 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Test_Job_With_TearDown
|
|
|
|
{
|
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
|
|
|
}
|
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
|
|
|
}
|