Skip to content

Commit 3a58258

Browse files
author
Andreas Fridlund
committed
PHP 8.2 compatability
1 parent 78a8b4a commit 3a58258

File tree

12 files changed

+46
-42
lines changed

12 files changed

+46
-42
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/
22
*.swp
33
phpunit.xml
44
composer.lock
5+
.phpunit.result.cache

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
3939
},
4040
"require-dev": {
41-
"phpunit/phpunit": "^5.7"
41+
"phpunit/phpunit": "^8.5"
4242
},
4343
"bin": [
4444
"bin/resque",

lib/Resque/Log.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function log($level, $message, array $context = array())
2727
if ($this->verbose) {
2828
fwrite(
2929
STDOUT,
30-
'[' . $level . '] [' . strftime('%T %Y-%m-%d') . '] ' . $this->interpolate($message, $context) . PHP_EOL
30+
'[' . $level . '] [' . date('H:i:s Y-m-d') . '] ' . $this->interpolate($message, $context) . PHP_EOL
3131
);
3232
return;
3333
}

lib/Resque/Redis.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Resque_Redis
1414
*/
1515
private static $defaultNamespace = 'resque:';
1616

17+
private $driver;
18+
1719
/**
1820
* A default host to connect to
1921
*/

lib/Resque/Worker.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
231231

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

@@ -252,7 +252,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
252252

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

lib/ResqueScheduler/Worker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function log($message)
139139
fwrite(STDOUT, "*** " . $message . "\n");
140140
}
141141
else if($this->logLevel == self::LOG_VERBOSE) {
142-
fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n");
142+
fwrite(STDOUT, "** [" . date('H:i:s Y-m-d') . "] " . $message . "\n");
143143
}
144144
}
145145

test/Resque/Tests/EventTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
class Resque_Tests_EventTest extends Resque_Tests_TestCase
1010
{
1111
private $callbacksHit = array();
12+
private $worker;
1213

13-
public function setUp()
14+
public function setUp(): void
1415
{
1516
Test_Job::$called = false;
1617

@@ -20,7 +21,7 @@ public function setUp()
2021
$this->worker->registerWorker();
2122
}
2223

23-
public function tearDown()
24+
public function tearDown(): void
2425
{
2526
Resque_Event::clearListeners();
2627
$this->callbacksHit = array();
@@ -147,7 +148,7 @@ public function beforePerformEventDontPerformCallback($instance)
147148
throw new Resque_Job_DontPerform;
148149
}
149150

150-
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $track = false)
151+
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $id, $track = false)
151152
{
152153
$this->callbacksHit[] = __FUNCTION__;
153154
throw new Resque_Job_DontCreate;
@@ -163,7 +164,7 @@ public function assertValidEventCallback($function, $job)
163164
$this->assertEquals($args[0], 'somevar');
164165
}
165166

166-
public function afterEnqueueEventCallback($class, $args)
167+
public function afterEnqueueEventCallback($class, $args, $queue, $id)
167168
{
168169
$this->callbacksHit[] = __FUNCTION__;
169170
$this->assertEquals('Test_Job', $class);
@@ -172,7 +173,7 @@ public function afterEnqueueEventCallback($class, $args)
172173
), $args);
173174
}
174175

175-
public function beforeEnqueueEventCallback($job)
176+
public function beforeEnqueueEventCallback($class, $args, $queue, $id)
176177
{
177178
$this->callbacksHit[] = __FUNCTION__;
178179
}

test/Resque/Tests/JobPIDTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Resque_Tests_JobPIDTest extends Resque_Tests_TestCase
1313
*/
1414
protected $worker;
1515

16-
public function setUp()
16+
public function setUp(): void
1717
{
1818
parent::setUp();
1919

test/Resque/Tests/JobStatusTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
1313
*/
1414
protected $worker;
1515

16-
public function setUp()
16+
public function setUp(): void
1717
{
1818
parent::setUp();
1919

@@ -103,4 +103,4 @@ public function testRecreatedJobWithTrackingStillTracksStatus()
103103
$newJob = Resque_Job::reserve('jobs');
104104
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $newJob->getStatus());
105105
}
106-
}
106+
}

test/Resque/Tests/JobTest.php

+18-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
1111
{
1212
protected $worker;
1313

14-
public function setUp()
14+
public function setUp(): void
1515
{
1616
parent::setUp();
1717

@@ -26,13 +26,12 @@ public function testJobCanBeQueued()
2626
$this->assertTrue((bool)Resque::enqueue('jobs', 'Test_Job'));
2727
}
2828

29-
/**
30-
* @expectedException Resque_RedisException
31-
*/
3229
public function testRedisErrorThrowsExceptionOnJobCreation()
3330
{
31+
$this->expectException(Resque_RedisException::class);
32+
3433
$mockCredis = $this->getMockBuilder('Credis_Client')
35-
->setMethods(['connect', '__call'])
34+
->onlyMethods(['connect', '__call'])
3635
->getMock();
3736
$mockCredis->expects($this->any())->method('__call')
3837
->will($this->throwException(new CredisException('failure')));
@@ -55,11 +54,10 @@ public function testQeueuedJobCanBeReserved()
5554
$this->assertEquals('Test_Job', $job->payload['class']);
5655
}
5756

58-
/**
59-
* @expectedException InvalidArgumentException
60-
*/
6157
public function testObjectArgumentsCannotBePassedToJob()
6258
{
59+
$this->expectException(InvalidArgumentException::class);
60+
6361
$args = new stdClass;
6462
$args->test = 'somevalue';
6563
Resque::enqueue('jobs', 'Test_Job', $args);
@@ -132,22 +130,20 @@ public function testFailedJobExceptionsAreCaught()
132130
$this->assertEquals(1, Resque_Stat::get('failed:'.$this->worker));
133131
}
134132

135-
/**
136-
* @expectedException Resque_Exception
137-
*/
138133
public function testJobWithoutPerformMethodThrowsException()
139134
{
135+
$this->expectException(Resque_Exception::class);
136+
140137
Resque::enqueue('jobs', 'Test_Job_Without_Perform_Method');
141138
$job = $this->worker->reserve();
142139
$job->worker = $this->worker;
143140
$job->perform();
144141
}
145142

146-
/**
147-
* @expectedException Resque_Exception
148-
*/
149143
public function testInvalidJobThrowsException()
150144
{
145+
$this->expectException(Resque_Exception::class);
146+
151147
Resque::enqueue('jobs', 'Invalid_Job');
152148
$job = $this->worker->reserve();
153149
$job->worker = $this->worker;
@@ -311,7 +307,7 @@ public function testDequeueWrongItemID2()
311307
{
312308
$queue = 'jobs';
313309
Resque::enqueue($queue, 'Test_Job_Dequeue');
314-
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
310+
Resque::enqueue($queue, 'Test_Job_Dequeue');
315311
$this->assertEquals(Resque::size($queue), 2);
316312
$test = array('Test_Job_Dequeue' => 'r4nD0mH4sh3dId');
317313
$this->assertEquals(Resque::dequeue($queue, $test), 0);
@@ -349,7 +345,7 @@ public function testDequeueSeveralItemsWithArgs()
349345
$this->assertEquals($removedItems, 2);
350346
$this->assertEquals(Resque::size($queue), 1);
351347
$item = Resque::pop($queue);
352-
$this->assertInternalType('array', $item['args']);
348+
$this->assertIsArray($item['args']);
353349
$this->assertEquals(10, $item['args'][0]['bar'], 'Wrong items were dequeued from queue!');
354350
}
355351

@@ -410,9 +406,12 @@ public function testDoNotUseFactoryToGetInstance()
410406
'args' => array(array())
411407
);
412408
$job = new Resque_Job('jobs', $payload);
413-
$factory = $this->getMock('Resque_Job_FactoryInterface');
414-
$testJob = $this->getMock('Resque_JobInterface');
415-
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
409+
/** @var $factory MockObject|Resque_Job_FactoryInterface */
410+
$factory = $this->createMock('Resque_Job_FactoryInterface');
411+
$testJob = $this->createMock('Resque_JobInterface');
412+
$factory->expects(self::never())
413+
->method('create')
414+
->will(self::returnValue($testJob));
416415
$instance = $job->getInstance();
417416
$this->assertInstanceOf('Resque_JobInterface', $instance);
418417
}

test/Resque/Tests/RedisTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
*/
99
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
1010
{
11-
/**
12-
* @expectedException Resque_RedisException
13-
*/
1411
public function testRedisExceptionsAreSurfaced()
1512
{
13+
$this->expectException(Resque_RedisException::class);
14+
1615
$mockCredis = $this->getMockBuilder('Credis_Client')
17-
->setMethods(['connect', '__call'])
16+
->onlyMethods(['connect', '__call'])
1817
->getMock();
1918
$mockCredis->expects($this->any())->method('__call')
2019
->will($this->throwException(new CredisException('failure')));
@@ -187,11 +186,11 @@ public function testParsingValidDsnString($dsn, $expected)
187186

188187
/**
189188
* @dataProvider bogusDsnStringProvider
190-
* @expectedException InvalidArgumentException
191189
*/
192190
public function testParsingBogusDsnStringThrowsException($dsn)
193191
{
192+
$this->expectException(InvalidArgumentException::class);
194193
// The next line should throw an InvalidArgumentException
195-
$result = Resque_Redis::parseDsn($dsn);
194+
Resque_Redis::parseDsn($dsn);
196195
}
197-
}
196+
}

test/Resque/Tests/TestCase.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
* @author Chris Boulton <[email protected]>
77
* @license http://www.opensource.org/licenses/mit-license.php
88
*/
9-
class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
9+
use PHPUnit\Framework\TestCase;
10+
11+
class Resque_Tests_TestCase extends TestCase
1012
{
1113
protected $resque;
1214
protected $redis;
1315

14-
public static function setUpBeforeClass()
16+
public static function setUpBeforeClass(): void
1517
{
1618
date_default_timezone_set('UTC');
1719
}
1820

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

0 commit comments

Comments
 (0)