diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 49244bb..628e8ee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,16 +4,18 @@ # Install git (the php image doesn't have it) which is required by composer apt-get update -yq - apt-get install git redis-server -y + apt-get install git wget -y - # Install phpunit, the tool that we will use for testing - curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar - chmod +x /usr/local/bin/phpunit + pecl install -o -f redis \ + && rm -rf /tmp/pear \ + && docker-php-ext-enable redis + docker-php-ext-install pcntl - # Install mysql driver - # Here you can install any other extension that you need - docker-php-ext-install redis + wget https://getcomposer.org/composer.phar + php composer.phar install +services: + - redis:latest # Test PHP 7.0 test:7.0: @@ -21,16 +23,20 @@ test:7.0: before_script: - *docker_boostrap script: + - curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-6.5.9.phar + - chmod +x /usr/local/bin/phpunit - phpunit --configuration phpunit.xml.dist tags: - docker -# Test PHP 7.2 +# Test PHP 7.1 test:7.1: image: php:7.1 before_script: - *docker_boostrap script: + - curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-7.5.9.phar + - chmod +x /usr/local/bin/phpunit - phpunit --configuration phpunit.xml.dist tags: - docker @@ -41,6 +47,20 @@ test:7.2: before_script: - *docker_boostrap script: + - curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar + - chmod +x /usr/local/bin/phpunit - phpunit --configuration phpunit.xml.dist tags: - - docker \ No newline at end of file + - docker + +# Test PHP 7.3 +test:7.3: + image: php:7.3 + before_script: + - *docker_boostrap + script: + - curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar + - chmod +x /usr/local/bin/phpunit + - phpunit --configuration phpunit.xml.dist + tags: + - docker diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e628f4..90225ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.4 (2019-06-02) +- Updated tests to run on GitLab CI. +- Can now run tests locally using `gitlab-runner exec docker test:7.0` + ## 1.4.3 (2018-07-16) - Updated README to include supervisor configuration. - Change logfile date format to `%Y-%m-%d %T`. diff --git a/README.md b/README.md index acac87b..79bc9a3 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,15 @@ not exit with a status code as 0 * Has built in support for `setUp` and `tearDown` methods, called pre and post jobs +On top of the original fork (chrisboulton/php-resque) I have added: + +* Custom log levels +* PHP7.0+ compatibility + + ## Requirements ## -* PHP 7.0+ (May work with 5.6+, Untested) +* PHP 7.0+ * phpredis * Redis 2.2+ diff --git a/composer.json b/composer.json index e53bff1..85352af 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "idanoo/php-resque", - "version": "1.4.3", + "version": "1.4.4", "type": "library", "description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby. Originally forked from chrisboulton/php-resque.", "keywords": ["job", "background", "redis", "resque"], diff --git a/test/Resque/Tests/TestCase.php b/test/Resque/Tests/TestCase.php index aa348d5..a428d12 100644 --- a/test/Resque/Tests/TestCase.php +++ b/test/Resque/Tests/TestCase.php @@ -21,8 +21,10 @@ class Resque_Tests_TestCase extends PHPUnit\Framework\TestCase public function setUp() { // Setup redis connection for testing. - $this->redis = new Credis_Client('localhost', '6379'); - Resque::setBackend('localhost'); + global $redisTestServer; + + $this->redis = new Credis_Client($redisTestServer, '6379'); + Resque::setBackend($redisTestServer); $this->redis->flushAll(); } } diff --git a/test/bootstrap.php b/test/bootstrap.php index a92611c..81b8e69 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -3,82 +3,30 @@ * Resque test bootstrap file - sets up a test environment. * * @package Resque/Tests - * @author Chris Boulton + * @author Daniel Mason * @license http://www.opensource.org/licenses/mit-license.php */ $loader = require __DIR__ . '/../vendor/autoload.php'; $loader->add('Resque_Tests', __DIR__); -define('TEST_MISC', realpath(__DIR__ . '/misc/')); -define('REDIS_CONF', TEST_MISC . '/redis.conf'); +# Redis configuration +global $redisTestServer; +$redisTestServer = getenv("REDIS_SERVER") ?? "redis"; +Resque::setBackend($redisTestServer); -// Attempt to start our own redis instance for tesitng. -exec('which redis-server', $output, $returnVar); -if ($returnVar != 0) { - echo "Cannot find redis-server in path. Please make sure redis is installed.\n"; - exit(1); +# 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."); } +$redisTest = null; -exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar); -usleep(500000); -if ($returnVar != 0) { - echo "Cannot start redis-server.\n"; - exit(1); -} - -// Get redis port from conf -$config = file_get_contents(REDIS_CONF); -if (!preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches)) { - echo "Could not determine redis port from redis.conf"; - exit(1); -} - -Resque::setBackend('localhost:' . $matches[1]); - -// Shutdown -function killRedis($pid) -{ - if (getmypid() !== $pid) { - return; // don't kill from a forked worker - } - $config = file_get_contents(REDIS_CONF); - if (!preg_match('#^\s*pidfile\s+([^\s]+)#m', $config, $matches)) { - return; - } - - $pidFile = TEST_MISC . '/' . $matches[1]; - if (file_exists($pidFile)) { - $pid = trim(file_get_contents($pidFile)); - posix_kill((int)$pid, 9); - - if (is_file($pidFile)) { - unlink($pidFile); - } - } - - // Remove the redis database - if (!preg_match('#^\s*dir\s+([^\s]+)#m', $config, $matches)) { - return; - } - $dir = $matches[1]; - - if (!preg_match('#^\s*dbfilename\s+([^\s]+)#m', $config, $matches)) { - return; - } - - $filename = TEST_MISC . '/' . $dir . '/' . $matches[1]; - if (is_file($filename)) { - unlink($filename); - } -} - -register_shutdown_function('killRedis', getmypid()); +# Cleanup forked workers cleanly if (function_exists('pcntl_signal')) { - // Override INT and TERM signals, so they do a clean shutdown and also - // clean up redis-server as well. function sigint() { exit; @@ -88,6 +36,7 @@ if (function_exists('pcntl_signal')) { pcntl_signal(SIGTERM, 'sigint'); } +# Bootstrap it class Test_Job { public static $called = false;