php-resque/tests/bootstrap.php

95 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2010-04-18 13:58:43 +00:00
<?php
namespace Resque\Test;
2010-04-18 13:58:43 +00:00
/**
* 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";
\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 {
$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')) {
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
class TestJob
2010-04-18 13:58:43 +00:00
{
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 FailingJobException extends \Exception
2010-04-18 13:58:43 +00:00
{
}
class FailingJob
2010-04-18 13:58:43 +00:00
{
public function perform()
{
throw new FailingJobException('Message!');
}
2010-04-18 13:58:43 +00:00
}
class TestJobWithoutPerformMethod
2010-04-18 13:58:43 +00:00
{
}
class TestJobWithSetUp
{
public static $called = false;
public $args = false;
public function setUp()
{
self::$called = true;
}
public function perform()
{
}
}
class TestJobWithTearDown
{
public static $called = false;
public $args = false;
public function perform()
{
}
public function tearDown()
{
self::$called = true;
}
2010-04-18 13:58:43 +00:00
}