Add setUp and tearDown callbacks for jobs

This commit is contained in:
Chris Boulton 2010-04-20 10:02:34 +10:00
parent 94fed1cfb4
commit 6e6d7ad859
6 changed files with 114 additions and 3 deletions

View file

@ -136,4 +136,36 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
$job->worker = $this->worker;
$job->perform();
}
public function testJobWithSetUpCallbackFiresSetUp()
{
$payload = array(
'class' => 'Test_Job_With_SetUp',
'args' => array(
'somevar',
'somevar2',
),
);
$job = new Resque_Job('jobs', $payload);
$job->perform();
$this->assertTrue(Test_Job_With_SetUp::$called);
$this->assertEquals($payload['args'], Test_Job_With_SetUp::$data);
}
public function testJobWithTearDownCallbackFiresSetUp()
{
$payload = array(
'class' => 'Test_Job_With_TearDown',
'args' => array(
'somevar',
'somevar2',
),
);
$job = new Resque_Job('jobs', $payload);
$job->perform();
$this->assertTrue(Test_Job_With_TearDown::$called);
$this->assertEquals($payload['args'], Test_Job_With_TearDown::$data);
}
}

View file

@ -113,4 +113,39 @@ class Failing_Job
class Test_Job_Without_Perform_Method
{
}
class Test_Job_With_SetUp
{
public static $called = false;
public static $data = false;
public function setUp($data)
{
self::$called = true;
self::$data = $data;
}
public function perform($data)
{
}
}
class Test_Job_With_TearDown
{
public static $called = false;
public static $data = false;
public function perform($data)
{
}
public function tearDown($data)
{
self::$called = true;
self::$data = $data;
}
}