Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for PHP 8.1 #62

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
include:
- php-versions: '8.0'
experimental: true
- php-versions: '8.1'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -21,7 +23,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit:5
tools: phpunit:8
extensions: redis

- name: Setup problem matchers for PHP
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
},
"require-dev": {
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^8.5"
},
"bin": [
"bin/resque",
Expand Down
2 changes: 1 addition & 1 deletion lib/Resque/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function log($level, $message, array $context = array())
if ($this->verbose) {
fwrite(
STDOUT,
'[' . $level . '] [' . strftime('%T %Y-%m-%d') . '] ' . $this->interpolate($message, $context) . PHP_EOL
'[' . $level . '] [' . date('G:i:s Y-m-d', time()) . '] ' . $this->interpolate($message, $context) . PHP_EOL
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Resque/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)

// Forked and we're the child. Or PCNTL is not installed. Run the job.
if ($this->child === 0 || $this->child === false || $this->child === -1) {
$status = 'Processing ' . $job->queue . ' since ' . strftime('%F %T');
$status = 'Processing ' . $job->queue . ' since ' . date('Y-m-d H:i:s ', time());
$this->updateProcLine($status);
$this->logger->log(Psr\Log\LogLevel::INFO, $status);

Expand All @@ -251,7 +251,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)

if ($this->child > 0) {
// Parent process, sit and wait
$status = 'Forked ' . $this->child . ' at ' . strftime('%F %T');
$status = 'Forked ' . $this->child . ' at ' . date('Y-m-d H:i:s ', time());
$this->updateProcLine($status);
$this->logger->log(Psr\Log\LogLevel::INFO, $status);

Expand Down
2 changes: 1 addition & 1 deletion lib/ResqueScheduler/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function log($message)
if ($this->logLevel == self::LOG_NORMAL) {
fwrite(STDOUT, "*** " . $message . "\n");
} elseif ($this->logLevel == self::LOG_VERBOSE) {
fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n");
fwrite(STDOUT, "** [" . date('H:i:s Y-m-d', time()) . "] " . $message . "\n");
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/Resque/Tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
{
private $callbacksHit = array();

public function setUp()
public function setUp(): void
{
Test_Job::$called = false;

Expand All @@ -23,7 +23,7 @@ public function setUp()
$this->worker->registerWorker();
}

public function tearDown()
public function tearDown(): void
{
Resque_Event::clearListeners();
$this->callbacksHit = array();
Expand Down Expand Up @@ -160,7 +160,7 @@ public function beforePerformEventDontPerformCallback($instance)
throw new Resque_Job_DontPerform;
}

public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $track = false)
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $id, $track = false)
{
$this->callbacksHit[] = __FUNCTION__;
throw new Resque_Job_DontCreate;
Expand All @@ -176,7 +176,7 @@ public function assertValidEventCallback($function, $job)
$this->assertEquals($args[0], 'somevar');
}

public function afterEnqueueEventCallback($class, $args)
public function afterEnqueueEventCallback($class, $args, $queue, $id)
{
$this->callbacksHit[] = __FUNCTION__;
$this->assertEquals('Test_Job', $class);
Expand All @@ -185,7 +185,7 @@ public function afterEnqueueEventCallback($class, $args)
), $args);
}

public function beforeEnqueueEventCallback($job)
public function beforeEnqueueEventCallback($class, $args, $queue, $id)
{
$this->callbacksHit[] = __FUNCTION__;
}
Expand Down
2 changes: 1 addition & 1 deletion test/Resque/Tests/JobPIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Resque_Tests_JobPIDTest extends Resque_Tests_TestCase
*/
protected $worker;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/Resque/Tests/JobStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
*/
protected $worker;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
24 changes: 10 additions & 14 deletions test/Resque/Tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
{
protected $worker;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -26,11 +26,10 @@ public function testJobCanBeQueued()
$this->assertTrue((bool)Resque::enqueue('jobs', 'Test_Job'));
}

/**
* @expectedException Resque_RedisException
*/
public function testRedisErrorThrowsExceptionOnJobCreation()
{
$this->expectException(Resque_RedisException::class);

$mockCredis = $this->getMockBuilder('Credis_Client')
->setMethods(['connect', '__call'])
->getMock();
Expand All @@ -55,11 +54,10 @@ public function testQeueuedJobCanBeReserved()
$this->assertEquals('Test_Job', $job->payload['class']);
}

/**
* @expectedException InvalidArgumentException
*/
public function testObjectArgumentsCannotBePassedToJob()
{
$this->expectException(InvalidArgumentException::class);

$args = new stdClass;
$args->test = 'somevalue';
Resque::enqueue('jobs', 'Test_Job', $args);
Expand Down Expand Up @@ -132,22 +130,20 @@ public function testFailedJobExceptionsAreCaught()
$this->assertEquals(1, Resque_Stat::get('failed:'.$this->worker));
}

/**
* @expectedException Resque_Exception
*/
public function testJobWithoutPerformMethodThrowsException()
{
$this->expectException(Resque_Exception::class);

Resque::enqueue('jobs', 'Test_Job_Without_Perform_Method');
$job = $this->worker->reserve();
$job->worker = $this->worker;
$job->perform();
}

/**
* @expectedException Resque_Exception
*/
public function testInvalidJobThrowsException()
{
$this->expectException(Resque_Exception::class);

Resque::enqueue('jobs', 'Invalid_Job');
$job = $this->worker->reserve();
$job->worker = $this->worker;
Expand Down Expand Up @@ -349,7 +345,7 @@ public function testDequeueSeveralItemsWithArgs()
$this->assertEquals($removedItems, 2);
$this->assertEquals(Resque::size($queue), 1);
$item = Resque::pop($queue);
$this->assertInternalType('array', $item['args']);
$this->assertIsArray($item['args']);
$this->assertEquals(10, $item['args'][0]['bar'], 'Wrong items were dequeued from queue!');
}

Expand Down
7 changes: 3 additions & 4 deletions test/Resque/Tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
*/
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
{
/**
* @expectedException Resque_RedisException
*/
public function testRedisExceptionsAreSurfaced()
{
$this->expectException(Resque_RedisException::class);

$mockCredis = $this->getMockBuilder('Credis_Client')
->setMethods(['connect', '__call'])
->getMock();
Expand Down Expand Up @@ -187,10 +186,10 @@ public function testParsingValidDsnString($dsn, $expected)

/**
* @dataProvider bogusDsnStringProvider
* @expectedException InvalidArgumentException
*/
public function testParsingBogusDsnStringThrowsException($dsn)
{
$this->expectException(InvalidArgumentException::class);
// The next line should throw an InvalidArgumentException
$result = Resque_Redis::parseDsn($dsn);
}
Expand Down
9 changes: 6 additions & 3 deletions test/Resque/Tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<?php

use PHPUnit\Framework\TestCase;

/**
* Resque test case class. Contains setup and teardown methods.
*
* @package Resque/Tests
* @author Chris Boulton <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
class Resque_Tests_TestCase extends TestCase
{
protected $resque;
protected $redis;
protected $logger;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
date_default_timezone_set('UTC');
}

public function setUp()
public function setUp(): void
{
$config = file_get_contents(REDIS_CONF);
preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches);
Expand Down