From de22db682686700f96544e089a23cbb1974c1d63 Mon Sep 17 00:00:00 2001 From: Sebastian Machuca Date: Thu, 6 Oct 2016 16:07:16 +1100 Subject: [PATCH] Making it compatible with PHP < 5.5 Making the factory receive the classname --- lib/Resque/Job.php | 2 +- lib/Resque/Job/FactoryInterface.php | 3 ++- test/Resque/Tests/JobTest.php | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 6c39e18..31952aa 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -182,7 +182,7 @@ class Resque_Job implements Resque_JobInterface } if ($this->jobFactory !== null) { - $this->instance = $this->jobFactory->create(); + $this->instance = $this->jobFactory->create($this->payload['class']); } else { $this->instance = new $this->payload['class']; } diff --git a/lib/Resque/Job/FactoryInterface.php b/lib/Resque/Job/FactoryInterface.php index 9a2b14c..89edbee 100644 --- a/lib/Resque/Job/FactoryInterface.php +++ b/lib/Resque/Job/FactoryInterface.php @@ -3,7 +3,8 @@ interface Resque_Job_FactoryInterface { /** + * @param $className * @return Resque_JobInterface */ - public function create(); + public function create($className); } diff --git a/test/Resque/Tests/JobTest.php b/test/Resque/Tests/JobTest.php index 1f2b428..32111d0 100644 --- a/test/Resque/Tests/JobTest.php +++ b/test/Resque/Tests/JobTest.php @@ -365,30 +365,30 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase public function testUseFactoryToGetJobInstance() { $payload = array( - 'class' => Some_Job_Class::class, + 'class' => 'Some_Job_Class', 'args' => null ); $job = new Resque_Job('jobs', $payload); - $factory = $this->getMock(Resque_Job_FactoryInterface::class); + $factory = $this->getMock('Resque_Job_FactoryInterface'); $job->setJobFactory($factory); - $testJob = $this->getMock(Resque_JobInterface::class); + $testJob = $this->getMock('Resque_JobInterface'); $factory->expects(self::once())->method('create')->will($this->returnValue($testJob)); $instance = $job->getInstance(); - $this->assertInstanceOf(Resque_JobInterface::class, $instance); + $this->assertInstanceOf('Resque_JobInterface', $instance); } public function testDoNotUseFactoryToGetInstance() { $payload = array( - 'class' => Some_Job_Class::class, + 'class' => 'Some_Job_Class', 'args' => null ); $job = new Resque_Job('jobs', $payload); - $factory = $this->getMock(Resque_Job_FactoryInterface::class); - $testJob = $this->getMock(Resque_JobInterface::class); + $factory = $this->getMock('Resque_Job_FactoryInterface'); + $testJob = $this->getMock('Resque_JobInterface'); $factory->expects(self::never())->method('create')->will(self::returnValue($testJob)); $instance = $job->getInstance(); - $this->assertInstanceOf(Resque_JobInterface::class, $instance); + $this->assertInstanceOf('Resque_JobInterface', $instance); } }