php-resque/test/bootstrap.php

99 lines
1.6 KiB
PHP
Raw Normal View History

2010-04-18 13:58:43 +00:00
<?php
/**
* Resque test bootstrap file - sets up a test environment.
*
* @package Resque/Tests
2019-06-02 10:21:42 +00:00
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
2010-04-18 13:58:43 +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
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
{
public static $called = false;
2011-03-27 07:42:46 +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
{
public function perform()
{
throw new Failing_Job_Exception('Message!');
}
2010-04-18 13:58:43 +00:00
}
class Test_Job_Without_Perform_Method
{
}
class Test_Job_With_SetUp
{
public static $called = false;
public $args = false;
public function setUp()
{
self::$called = true;
}
public function perform()
{
}
}
class Test_Job_With_TearDown
{
public static $called = false;
public $args = false;
public function perform()
{
}
public function tearDown()
{
self::$called = true;
}
2010-04-18 13:58:43 +00:00
}