Skip to content

Commit 8f542e5

Browse files
author
Sebastian Machuca
committed
Making the factory responsible to set the arguments and the queue
1 parent de22db6 commit 8f542e5

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

lib/Resque/Job.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ public function getInstance()
182182
}
183183

184184
if ($this->jobFactory !== null) {
185-
$this->instance = $this->jobFactory->create($this->payload['class']);
186-
} else {
187-
$this->instance = new $this->payload['class'];
185+
$this->instance = $this->jobFactory->create($this->payload['class'], $this->getArguments(), $this->queue);
186+
return $this->instance;
188187
}
189-
$this->instance->job = $this;
190-
$this->instance->args = $this->getArguments();
191-
$this->instance->queue = $this->queue;
188+
$this->instance = new $this->payload['class'];
189+
$this->instance->job = $this;
190+
$this->instance->args = $this->getArguments();
191+
$this->instance->queue = $this->queue;
192+
192193
return $this->instance;
193194
}
194195

lib/Resque/Job/FactoryInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ interface Resque_Job_FactoryInterface
44
{
55
/**
66
* @param $className
7+
* @param array $args
8+
* @param $queue
79
* @return Resque_JobInterface
810
*/
9-
public function create($className);
11+
public function create($className, array $args, $queue);
1012
}

test/Resque/Tests/JobTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,8 @@ public function testUseFactoryToGetJobInstance()
369369
'args' => null
370370
);
371371
$job = new Resque_Job('jobs', $payload);
372-
$factory = $this->getMock('Resque_Job_FactoryInterface');
372+
$factory = new Some_Stub_Factory();
373373
$job->setJobFactory($factory);
374-
$testJob = $this->getMock('Resque_JobInterface');
375-
$factory->expects(self::once())->method('create')->will($this->returnValue($testJob));
376374
$instance = $job->getInstance();
377375
$this->assertInstanceOf('Resque_JobInterface', $instance);
378376
}
@@ -403,3 +401,18 @@ public function perform()
403401
return true;
404402
}
405403
}
404+
405+
class Some_Stub_Factory implements Resque_Job_FactoryInterface
406+
{
407+
408+
/**
409+
* @param $className
410+
* @param array $args
411+
* @param $queue
412+
* @return Resque_JobInterface
413+
*/
414+
public function create($className, array $args, $queue)
415+
{
416+
return new Some_Job_Class();
417+
}
418+
}

0 commit comments

Comments
 (0)