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

Update to PHPUnit 9.5 and PHP 7.3 #88

Merged
merged 7 commits into from
Mar 4, 2025
Merged
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@v4
Expand Down Expand Up @@ -40,7 +42,7 @@ jobs:

phpcs:
runs-on: ubuntu-latest
continue-on-error: true
continue-on-error: false
name: "PHPCS"
steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.3.0",
"colinmollenhour/credis": "~1.7",
"psr/log": ">=1.1.0"
},
Expand All @@ -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": ">=9.0 <9.6",
"squizlabs/php_codesniffer": "^3.10",
"phpstan/phpstan": "^1.12"
},
Expand Down
8 changes: 4 additions & 4 deletions lib/Job/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*/
class Status
{
const STATUS_WAITING = 1;
const STATUS_RUNNING = 2;
const STATUS_FAILED = 3;
const STATUS_COMPLETE = 4;
public const STATUS_WAITING = 1;
public const STATUS_RUNNING = 2;
public const STATUS_FAILED = 3;
public const STATUS_COMPLETE = 4;

/**
* @var string The prefix of the job status id.
Expand Down
6 changes: 3 additions & 3 deletions lib/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class Redis
/**
* A default host to connect to
*/
const DEFAULT_HOST = 'localhost';
protected const DEFAULT_HOST = 'localhost';

/**
* The default Redis port
*/
const DEFAULT_PORT = 6379;
protected const DEFAULT_PORT = 6379;

/**
* The default Redis Database number
*/
const DEFAULT_DATABASE = 0;
protected const DEFAULT_DATABASE = 0;

/**
* Connection driver
Expand Down
4 changes: 2 additions & 2 deletions lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
class Resque
{
const VERSION = '1.2';
public const VERSION = '1.2';

const DEFAULT_INTERVAL = 5;
public const DEFAULT_INTERVAL = 5;

/**
* @var Redis Instance of Resque\Redis that talks to redis.
Expand Down
2 changes: 1 addition & 1 deletion lib/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class Scheduler
{
const VERSION = "0.1";
public const VERSION = "0.1";

/**
* Enqueue a job in a given number of seconds from now.
Expand Down
6 changes: 3 additions & 3 deletions lib/Worker/SchedulerWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
class SchedulerWorker
{
const LOG_NONE = 0;
const LOG_NORMAL = 1;
const LOG_VERBOSE = 2;
public const LOG_NONE = 0;
public const LOG_NORMAL = 1;
public const LOG_VERBOSE = 2;

/**
* @var int Current log level of this worker.
Expand Down
12 changes: 7 additions & 5 deletions test/Resque/Tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class EventTest extends ResqueTestCase
{
private $callbacksHit = array();

public function setUp()
private $worker;

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

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

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

public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $track = false)
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $id, $track = false)
{
$this->callbacksHit[] = __FUNCTION__;
throw new DoNotCreateException;
Expand All @@ -187,7 +189,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 @@ -196,7 +198,7 @@ public function afterEnqueueEventCallback($class, $args)
), $args);
}

public function beforeEnqueueEventCallback($job)
public function beforeEnqueueEventCallback($class, $args, $queue, $id)
{
$this->callbacksHit[] = __FUNCTION__;
}
Expand Down
24 changes: 10 additions & 14 deletions test/Resque/Tests/JobHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JobHandlerTest extends ResqueTestCase
{
protected $worker;

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

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

/**
* @expectedException \Resque\Exceptions\RedisException
*/
public function testRedisErrorThrowsExceptionOnJobCreation()
{
$this->expectException('\Resque\Exceptions\RedisException');

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

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

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

/**
* @expectedException \Resque\Exceptions\ResqueException
*/
public function testJobWithoutPerformMethodThrowsException()
{
$this->expectException('\Resque\Exceptions\ResqueException');

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

/**
* @expectedException Resque\Exceptions\ResqueException
*/
public function testInvalidJobThrowsException()
{
$this->expectException('Resque\Exceptions\ResqueException');

Resque::enqueue('jobs', 'Invalid_Job');
$job = $this->worker->reserve();
$job->worker = $this->worker;
Expand Down Expand Up @@ -363,7 +359,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
2 changes: 1 addition & 1 deletion test/Resque/Tests/JobPIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JobPIDTest extends ResqueTestCase
*/
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 @@ -21,7 +21,7 @@ class JobStatusTest extends ResqueTestCase
*/
protected $worker;

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

Expand Down
16 changes: 8 additions & 8 deletions test/Resque/Tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/
class RedisTest extends ResqueTestCase
{
/**
* @expectedException \Resque\Exceptions\RedisException
*/
public function testRedisExceptionsAreSurfaced()
{
$this->expectException('\Resque\Exceptions\RedisException');

$mockCredis = $this->getMockBuilder('Credis_Client')
->setMethods(['connect', '__call'])
->getMock();
Expand All @@ -43,14 +42,14 @@ public function validDsnStringProvider()
// Input , Expected output
array('', array(
'localhost',
Redis::DEFAULT_PORT,
6379,
false,
false, false,
array(),
)),
array('localhost', array(
'localhost',
Redis::DEFAULT_PORT,
6379,
false,
false, false,
array(),
Expand All @@ -71,14 +70,14 @@ public function validDsnStringProvider()
)),
array('redis://foobar', array(
'foobar',
Redis::DEFAULT_PORT,
6379,
false,
false, false,
array(),
)),
array('redis://foobar/', array(
'foobar',
Redis::DEFAULT_PORT,
6379,
false,
false, false,
array(),
Expand Down Expand Up @@ -194,10 +193,11 @@ public function testParsingValidDsnString($dsn, $expected)

/**
* @dataProvider bogusDsnStringProvider
* @expectedException InvalidArgumentException
*/
public function testParsingBogusDsnStringThrowsException($dsn)
{
$this->expectException('InvalidArgumentException');

// The next line should throw an InvalidArgumentException
$result = Redis::parseDsn($dsn);
}
Expand Down
8 changes: 4 additions & 4 deletions test/Resque/Tests/ResqueTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Resque\Tests;

use \Resque\Resque;
use \PHPUnit_Framework_TestCase;
use \PHPUnit\Framework\TestCase;
use \Credis_Client;

/**
Expand All @@ -13,18 +13,18 @@
* @author Chris Boulton <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class ResqueTestCase extends PHPUnit_Framework_TestCase
class ResqueTestCase 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