BIG-28720 Allowing to use a factory instead of manually instantite the Jobs

This commit is contained in:
Sebastian Machuca 2016-10-06 12:49:15 +11:00
parent 15a14d8a86
commit 7d2ce1bc8b
No known key found for this signature in database
GPG key ID: 4B3DA17F9CCF39DE
5 changed files with 106 additions and 22 deletions

View file

@ -362,4 +362,44 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
$this->assertEquals(Resque::size($queue), 2);
}
public function testUseFactoryToGetJobInstance()
{
$payload = array(
'class' => Some_Job_Class::class,
'args' => null
);
$job = new Resque_Job('jobs', $payload);
$factory = $this->getMock(Resque_Job_FactoryInterface::class);
$job->setJobFactory($factory);
$testJob = $this->getMock(Resque_JobInterface::class);
$factory->expects(self::once())->method('create')->will($this->returnValue($testJob));
$instance = $job->getInstance();
$this->assertInstanceOf(Resque_JobInterface::class, $instance);
}
public function testDoNotUseFactoryToGetInstance()
{
$payload = array(
'class' => Some_Job_Class::class,
'args' => null
);
$job = new Resque_Job('jobs', $payload);
$factory = $this->getMock(Resque_Job_FactoryInterface::class);
$testJob = $this->getMock(Resque_JobInterface::class);
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
$instance = $job->getInstance();
$this->assertInstanceOf(Resque_JobInterface::class, $instance);
}
}
class Some_Job_Class implements Resque_JobInterface
{
/**
* @return bool
*/
public function perform()
{
return true;
}
}

View file

@ -11,6 +11,11 @@ class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
protected $resque;
protected $redis;
public static function setUpBeforeClass()
{
date_default_timezone_set('UTC');
}
public function setUp()
{
$config = file_get_contents(REDIS_CONF);
@ -20,4 +25,4 @@ class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
// Flush redis
$this->redis->flushAll();
}
}
}