diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 31952aa..1465b36 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -182,13 +182,14 @@ class Resque_Job implements Resque_JobInterface } if ($this->jobFactory !== null) { - $this->instance = $this->jobFactory->create($this->payload['class']); - } else { - $this->instance = new $this->payload['class']; + $this->instance = $this->jobFactory->create($this->payload['class'], $this->getArguments(), $this->queue); + return $this->instance; } - $this->instance->job = $this; - $this->instance->args = $this->getArguments(); - $this->instance->queue = $this->queue; + $this->instance = new $this->payload['class']; + $this->instance->job = $this; + $this->instance->args = $this->getArguments(); + $this->instance->queue = $this->queue; + return $this->instance; } diff --git a/lib/Resque/Job/FactoryInterface.php b/lib/Resque/Job/FactoryInterface.php index 89edbee..d12211d 100644 --- a/lib/Resque/Job/FactoryInterface.php +++ b/lib/Resque/Job/FactoryInterface.php @@ -4,7 +4,9 @@ interface Resque_Job_FactoryInterface { /** * @param $className + * @param array $args + * @param $queue * @return Resque_JobInterface */ - public function create($className); + public function create($className, array $args, $queue); } diff --git a/test/Resque/Tests/JobTest.php b/test/Resque/Tests/JobTest.php index 32111d0..a71e6f0 100644 --- a/test/Resque/Tests/JobTest.php +++ b/test/Resque/Tests/JobTest.php @@ -369,10 +369,8 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase 'args' => null ); $job = new Resque_Job('jobs', $payload); - $factory = $this->getMock('Resque_Job_FactoryInterface'); + $factory = new Some_Stub_Factory(); $job->setJobFactory($factory); - $testJob = $this->getMock('Resque_JobInterface'); - $factory->expects(self::once())->method('create')->will($this->returnValue($testJob)); $instance = $job->getInstance(); $this->assertInstanceOf('Resque_JobInterface', $instance); } @@ -403,3 +401,18 @@ class Some_Job_Class implements Resque_JobInterface return true; } } + +class Some_Stub_Factory implements Resque_Job_FactoryInterface +{ + + /** + * @param $className + * @param array $args + * @param $queue + * @return Resque_JobInterface + */ + public function create($className, array $args, $queue) + { + return new Some_Job_Class(); + } +}