mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 00:11:53 +00:00
Making it compatible with PHP < 5.5
Making the factory receive the classname
This commit is contained in:
parent
7d2ce1bc8b
commit
de22db6826
@ -182,7 +182,7 @@ class Resque_Job implements Resque_JobInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->jobFactory !== null) {
|
if ($this->jobFactory !== null) {
|
||||||
$this->instance = $this->jobFactory->create();
|
$this->instance = $this->jobFactory->create($this->payload['class']);
|
||||||
} else {
|
} else {
|
||||||
$this->instance = new $this->payload['class'];
|
$this->instance = new $this->payload['class'];
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
interface Resque_Job_FactoryInterface
|
interface Resque_Job_FactoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param $className
|
||||||
* @return Resque_JobInterface
|
* @return Resque_JobInterface
|
||||||
*/
|
*/
|
||||||
public function create();
|
public function create($className);
|
||||||
}
|
}
|
||||||
|
@ -365,30 +365,30 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
public function testUseFactoryToGetJobInstance()
|
public function testUseFactoryToGetJobInstance()
|
||||||
{
|
{
|
||||||
$payload = array(
|
$payload = array(
|
||||||
'class' => Some_Job_Class::class,
|
'class' => 'Some_Job_Class',
|
||||||
'args' => null
|
'args' => null
|
||||||
);
|
);
|
||||||
$job = new Resque_Job('jobs', $payload);
|
$job = new Resque_Job('jobs', $payload);
|
||||||
$factory = $this->getMock(Resque_Job_FactoryInterface::class);
|
$factory = $this->getMock('Resque_Job_FactoryInterface');
|
||||||
$job->setJobFactory($factory);
|
$job->setJobFactory($factory);
|
||||||
$testJob = $this->getMock(Resque_JobInterface::class);
|
$testJob = $this->getMock('Resque_JobInterface');
|
||||||
$factory->expects(self::once())->method('create')->will($this->returnValue($testJob));
|
$factory->expects(self::once())->method('create')->will($this->returnValue($testJob));
|
||||||
$instance = $job->getInstance();
|
$instance = $job->getInstance();
|
||||||
$this->assertInstanceOf(Resque_JobInterface::class, $instance);
|
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDoNotUseFactoryToGetInstance()
|
public function testDoNotUseFactoryToGetInstance()
|
||||||
{
|
{
|
||||||
$payload = array(
|
$payload = array(
|
||||||
'class' => Some_Job_Class::class,
|
'class' => 'Some_Job_Class',
|
||||||
'args' => null
|
'args' => null
|
||||||
);
|
);
|
||||||
$job = new Resque_Job('jobs', $payload);
|
$job = new Resque_Job('jobs', $payload);
|
||||||
$factory = $this->getMock(Resque_Job_FactoryInterface::class);
|
$factory = $this->getMock('Resque_Job_FactoryInterface');
|
||||||
$testJob = $this->getMock(Resque_JobInterface::class);
|
$testJob = $this->getMock('Resque_JobInterface');
|
||||||
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
|
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
|
||||||
$instance = $job->getInstance();
|
$instance = $job->getInstance();
|
||||||
$this->assertInstanceOf(Resque_JobInterface::class, $instance);
|
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user