mirror of
https://github.com/idanoo/php-resque
synced 2025-07-01 05:32:20 +00:00
- Reformatted files to PSR2 standard
- Removed credis for native phpredis - Tidied up some docs - Setting up new travis.ci build
This commit is contained in:
parent
065d5a4c63
commit
ae84530132
30 changed files with 3724 additions and 2682 deletions
|
@ -1,199 +1,201 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque_Event tests.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
{
|
||||
private $callbacksHit = array();
|
||||
private $callbacksHit = array();
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Test_Job::$called = false;
|
||||
public function setUp()
|
||||
{
|
||||
Test_Job::$called = false;
|
||||
|
||||
// Register a worker to test with
|
||||
$this->worker = new Resque_Worker('jobs');
|
||||
$this->worker->setLogger(new Resque_Log());
|
||||
$this->worker->registerWorker();
|
||||
}
|
||||
// Register a worker to test with
|
||||
$this->worker = new Resque_Worker('jobs');
|
||||
$this->worker->setLogger(new Resque_Log());
|
||||
$this->worker->registerWorker();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Resque_Event::clearListeners();
|
||||
$this->callbacksHit = array();
|
||||
}
|
||||
public function tearDown()
|
||||
{
|
||||
Resque_Event::clearListeners();
|
||||
$this->callbacksHit = array();
|
||||
}
|
||||
|
||||
public function getEventTestJob()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Test_Job',
|
||||
'args' => array(
|
||||
array('somevar'),
|
||||
),
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->worker = $this->worker;
|
||||
return $job;
|
||||
}
|
||||
public function getEventTestJob()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Test_Job',
|
||||
'args' => array(
|
||||
array('somevar'),
|
||||
),
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->worker = $this->worker;
|
||||
return $job;
|
||||
}
|
||||
|
||||
public function eventCallbackProvider()
|
||||
{
|
||||
return array(
|
||||
array('beforePerform', 'beforePerformEventCallback'),
|
||||
array('afterPerform', 'afterPerformEventCallback'),
|
||||
array('afterFork', 'afterForkEventCallback'),
|
||||
);
|
||||
}
|
||||
public function eventCallbackProvider()
|
||||
{
|
||||
return array(
|
||||
array('beforePerform', 'beforePerformEventCallback'),
|
||||
array('afterPerform', 'afterPerformEventCallback'),
|
||||
array('afterFork', 'afterForkEventCallback'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider eventCallbackProvider
|
||||
*/
|
||||
public function testEventCallbacksFire($event, $callback)
|
||||
{
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
/**
|
||||
* @dataProvider eventCallbackProvider
|
||||
*/
|
||||
public function testEventCallbacksFire($event, $callback)
|
||||
{
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->perform($job);
|
||||
$this->worker->work(0);
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->perform($job);
|
||||
$this->worker->work(0);
|
||||
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
||||
}
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
|
||||
public function testBeforeForkEventCallbackFires()
|
||||
{
|
||||
$event = 'beforeFork';
|
||||
$callback = 'beforeForkEventCallback';
|
||||
public function testBeforeForkEventCallbackFires()
|
||||
{
|
||||
$event = 'beforeFork';
|
||||
$callback = 'beforeForkEventCallback';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
'somevar'
|
||||
));
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->work(0);
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
||||
}
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
'somevar'
|
||||
));
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->work(0);
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
|
||||
public function testBeforeEnqueueEventCallbackFires()
|
||||
{
|
||||
$event = 'beforeEnqueue';
|
||||
$callback = 'beforeEnqueueEventCallback';
|
||||
public function testBeforeEnqueueEventCallbackFires()
|
||||
{
|
||||
$event = 'beforeEnqueue';
|
||||
$callback = 'beforeEnqueueEventCallback';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
'somevar'
|
||||
));
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
||||
}
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
'somevar'
|
||||
));
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
|
||||
public function testBeforePerformEventCanStopWork()
|
||||
{
|
||||
$callback = 'beforePerformEventDontPerformCallback';
|
||||
Resque_Event::listen('beforePerform', array($this, $callback));
|
||||
public function testBeforePerformEventCanStopWork()
|
||||
{
|
||||
$callback = 'beforePerformEventDontPerformCallback';
|
||||
Resque_Event::listen('beforePerform', array($this, $callback));
|
||||
|
||||
$job = $this->getEventTestJob();
|
||||
$job = $this->getEventTestJob();
|
||||
|
||||
$this->assertFalse($job->perform());
|
||||
$this->assertContains($callback, $this->callbacksHit, $callback . ' callback was not called');
|
||||
$this->assertFalse(Test_Job::$called, 'Job was still performed though Resque_Job_DontPerform was thrown');
|
||||
}
|
||||
$this->assertFalse($job->perform());
|
||||
$this->assertContains($callback, $this->callbacksHit, $callback . ' callback was not called');
|
||||
$this->assertFalse(Test_Job::$called, 'Job was still performed though Resque_Job_DontPerform was thrown');
|
||||
}
|
||||
|
||||
public function testBeforeEnqueueEventStopsJobCreation()
|
||||
{
|
||||
$callback = 'beforeEnqueueEventDontCreateCallback';
|
||||
Resque_Event::listen('beforeEnqueue', array($this, $callback));
|
||||
Resque_Event::listen('afterEnqueue', array($this, 'afterEnqueueEventCallback'));
|
||||
public function testBeforeEnqueueEventStopsJobCreation()
|
||||
{
|
||||
$callback = 'beforeEnqueueEventDontCreateCallback';
|
||||
Resque_Event::listen('beforeEnqueue', array($this, $callback));
|
||||
Resque_Event::listen('afterEnqueue', array($this, 'afterEnqueueEventCallback'));
|
||||
|
||||
$result = Resque::enqueue('test_job', 'TestClass');
|
||||
$this->assertContains($callback, $this->callbacksHit, $callback . ' callback was not called');
|
||||
$this->assertNotContains('afterEnqueueEventCallback', $this->callbacksHit, 'afterEnqueue was still called, even though it should not have been');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
$result = Resque::enqueue('test_job', 'TestClass');
|
||||
$this->assertContains($callback, $this->callbacksHit, $callback . ' callback was not called');
|
||||
$this->assertNotContains('afterEnqueueEventCallback', $this->callbacksHit, 'afterEnqueue was still called, even though it should not have been');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testAfterEnqueueEventCallbackFires()
|
||||
{
|
||||
$callback = 'afterEnqueueEventCallback';
|
||||
$event = 'afterEnqueue';
|
||||
public function testAfterEnqueueEventCallbackFires()
|
||||
{
|
||||
$callback = 'afterEnqueueEventCallback';
|
||||
$event = 'afterEnqueue';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
'somevar'
|
||||
));
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
||||
}
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
'somevar'
|
||||
));
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
|
||||
public function testStopListeningRemovesListener()
|
||||
{
|
||||
$callback = 'beforePerformEventCallback';
|
||||
$event = 'beforePerform';
|
||||
public function testStopListeningRemovesListener()
|
||||
{
|
||||
$callback = 'beforePerformEventCallback';
|
||||
$event = 'beforePerform';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque_Event::stopListening($event, array($this, $callback));
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque_Event::stopListening($event, array($this, $callback));
|
||||
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->perform($job);
|
||||
$this->worker->work(0);
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->perform($job);
|
||||
$this->worker->work(0);
|
||||
|
||||
$this->assertNotContains($callback, $this->callbacksHit,
|
||||
$event . ' callback (' . $callback .') was called though Resque_Event::stopListening was called'
|
||||
);
|
||||
}
|
||||
$this->assertNotContains($callback, $this->callbacksHit,
|
||||
$event . ' callback (' . $callback . ') was called though Resque_Event::stopListening was called'
|
||||
);
|
||||
}
|
||||
|
||||
public function beforePerformEventDontPerformCallback($instance)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
throw new Resque_Job_DontPerform;
|
||||
}
|
||||
public function beforePerformEventDontPerformCallback($instance)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
throw new Resque_Job_DontPerform;
|
||||
}
|
||||
|
||||
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $track = false)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
throw new Resque_Job_DontCreate;
|
||||
}
|
||||
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $track = false)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
throw new Resque_Job_DontCreate;
|
||||
}
|
||||
|
||||
public function assertValidEventCallback($function, $job)
|
||||
{
|
||||
$this->callbacksHit[] = $function;
|
||||
if (!$job instanceof Resque_Job) {
|
||||
$this->fail('Callback job argument is not an instance of Resque_Job');
|
||||
}
|
||||
$args = $job->getArguments();
|
||||
$this->assertEquals($args[0], 'somevar');
|
||||
}
|
||||
public function assertValidEventCallback($function, $job)
|
||||
{
|
||||
$this->callbacksHit[] = $function;
|
||||
if (!$job instanceof Resque_Job) {
|
||||
$this->fail('Callback job argument is not an instance of Resque_Job');
|
||||
}
|
||||
$args = $job->getArguments();
|
||||
$this->assertEquals($args[0], 'somevar');
|
||||
}
|
||||
|
||||
public function afterEnqueueEventCallback($class, $args)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
$this->assertEquals('Test_Job', $class);
|
||||
$this->assertEquals(array(
|
||||
'somevar',
|
||||
), $args);
|
||||
}
|
||||
public function afterEnqueueEventCallback($class, $args)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
$this->assertEquals('Test_Job', $class);
|
||||
$this->assertEquals(array(
|
||||
'somevar',
|
||||
), $args);
|
||||
}
|
||||
|
||||
public function beforeEnqueueEventCallback($job)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
}
|
||||
public function beforeEnqueueEventCallback($job)
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
}
|
||||
|
||||
public function beforePerformEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
public function beforePerformEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
|
||||
public function afterPerformEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
public function afterPerformEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
|
||||
public function beforeForkEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
public function beforeForkEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
|
||||
public function afterForkEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
public function afterForkEventCallback($job)
|
||||
{
|
||||
$this->assertValidEventCallback(__FUNCTION__, $job);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque_Job_Status tests.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -13,94 +15,94 @@ class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
|
|||
*/
|
||||
protected $worker;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Register a worker to test with
|
||||
$this->worker = new Resque_Worker('jobs');
|
||||
$this->worker->setLogger(new Resque_Log());
|
||||
}
|
||||
// Register a worker to test with
|
||||
$this->worker = new Resque_Worker('jobs');
|
||||
$this->worker->setLogger(new Resque_Log());
|
||||
}
|
||||
|
||||
public function testJobStatusCanBeTracked()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertTrue($status->isTracking());
|
||||
}
|
||||
public function testJobStatusCanBeTracked()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertTrue($status->isTracking());
|
||||
}
|
||||
|
||||
public function testJobStatusIsReturnedViaJobInstance()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $job->getStatus());
|
||||
}
|
||||
public function testJobStatusIsReturnedViaJobInstance()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $job->getStatus());
|
||||
}
|
||||
|
||||
public function testQueuedJobReturnsQueuedStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $status->get());
|
||||
}
|
||||
public function testQueuedJobReturnsQueuedStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $status->get());
|
||||
}
|
||||
|
||||
public function testRunningJobReturnsRunningStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Failing_Job', null, true);
|
||||
$job = $this->worker->reserve();
|
||||
$this->worker->workingOn($job);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_RUNNING, $status->get());
|
||||
}
|
||||
public function testRunningJobReturnsRunningStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Failing_Job', null, true);
|
||||
$job = $this->worker->reserve();
|
||||
$this->worker->workingOn($job);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_RUNNING, $status->get());
|
||||
}
|
||||
|
||||
public function testFailedJobReturnsFailedStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Failing_Job', null, true);
|
||||
$this->worker->work(0);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_FAILED, $status->get());
|
||||
}
|
||||
public function testFailedJobReturnsFailedStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Failing_Job', null, true);
|
||||
$this->worker->work(0);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_FAILED, $status->get());
|
||||
}
|
||||
|
||||
public function testCompletedJobReturnsCompletedStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$this->worker->work(0);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_COMPLETE, $status->get());
|
||||
}
|
||||
public function testCompletedJobReturnsCompletedStatus()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$this->worker->work(0);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_COMPLETE, $status->get());
|
||||
}
|
||||
|
||||
public function testStatusIsNotTrackedWhenToldNotTo()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, false);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertFalse($status->isTracking());
|
||||
}
|
||||
public function testStatusIsNotTrackedWhenToldNotTo()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, false);
|
||||
$status = new Resque_Job_Status($token);
|
||||
$this->assertFalse($status->isTracking());
|
||||
}
|
||||
|
||||
public function testStatusTrackingCanBeStopped()
|
||||
{
|
||||
Resque_Job_Status::create('test');
|
||||
$status = new Resque_Job_Status('test');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $status->get());
|
||||
$status->stop();
|
||||
$this->assertFalse($status->get());
|
||||
}
|
||||
public function testStatusTrackingCanBeStopped()
|
||||
{
|
||||
Resque_Job_Status::create('test');
|
||||
$status = new Resque_Job_Status('test');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $status->get());
|
||||
$status->stop();
|
||||
$this->assertFalse($status->get());
|
||||
}
|
||||
|
||||
public function testRecreatedJobWithTrackingStillTracksStatus()
|
||||
{
|
||||
$originalToken = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$job = $this->worker->reserve();
|
||||
public function testRecreatedJobWithTrackingStillTracksStatus()
|
||||
{
|
||||
$originalToken = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$job = $this->worker->reserve();
|
||||
|
||||
// Mark this job as being worked on to ensure that the new status is still
|
||||
// waiting.
|
||||
$this->worker->workingOn($job);
|
||||
// Mark this job as being worked on to ensure that the new status is still
|
||||
// waiting.
|
||||
$this->worker->workingOn($job);
|
||||
|
||||
// Now recreate it
|
||||
$newToken = $job->recreate();
|
||||
// Now recreate it
|
||||
$newToken = $job->recreate();
|
||||
|
||||
// Make sure we've got a new job returned
|
||||
$this->assertNotEquals($originalToken, $newToken);
|
||||
// Make sure we've got a new job returned
|
||||
$this->assertNotEquals($originalToken, $newToken);
|
||||
|
||||
// Now check the status of the new job
|
||||
$newJob = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $newJob->getStatus());
|
||||
}
|
||||
// Now check the status of the new job
|
||||
$newJob = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $newJob->getStatus());
|
||||
}
|
||||
}
|
|
@ -3,444 +3,446 @@
|
|||
/**
|
||||
* Resque_Job tests.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
{
|
||||
protected $worker;
|
||||
protected $worker;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Register a worker to test with
|
||||
$this->worker = new Resque_Worker('jobs');
|
||||
$this->worker->setLogger(new Resque_Log());
|
||||
$this->worker->registerWorker();
|
||||
}
|
||||
// Register a worker to test with
|
||||
$this->worker = new Resque_Worker('jobs');
|
||||
$this->worker->setLogger(new Resque_Log());
|
||||
$this->worker->registerWorker();
|
||||
}
|
||||
|
||||
public function testJobCanBeQueued()
|
||||
{
|
||||
$this->assertTrue((bool)Resque::enqueue('jobs', 'Test_Job'));
|
||||
}
|
||||
public function testJobCanBeQueued()
|
||||
{
|
||||
$this->assertTrue((bool)Resque::enqueue('jobs', 'Test_Job'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Resque_RedisException
|
||||
*/
|
||||
public function testRedisErrorThrowsExceptionOnJobCreation()
|
||||
{
|
||||
$mockCredis = $this->getMockBuilder('Credis_Client')
|
||||
->setMethods(['connect', '__call'])
|
||||
->getMock();
|
||||
$mockCredis->expects($this->any())->method('__call')
|
||||
->will($this->throwException(new CredisException('failure')));
|
||||
// public function testRedisErrorThrowsExceptionOnJobCreation()
|
||||
// {
|
||||
// $mockCredis = $this->getMockBuilder('Credis_Client')
|
||||
// ->setMethods(['connect', '__call'])
|
||||
// ->getMock();
|
||||
// $mockCredis->expects($this->any())->method('__call')
|
||||
// ->will($this->throwException(new CredisException('failure')));
|
||||
//
|
||||
// Resque::setBackend(function($database) use ($mockCredis) {
|
||||
// return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||
// });
|
||||
// Resque::enqueue('jobs', 'This is a test');
|
||||
// }
|
||||
|
||||
Resque::setBackend(function($database) use ($mockCredis) {
|
||||
return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||
});
|
||||
Resque::enqueue('jobs', 'This is a test');
|
||||
}
|
||||
public function testQeueuedJobCanBeReserved()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Test_Job');
|
||||
|
||||
public function testQeueuedJobCanBeReserved()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Test_Job');
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
if ($job == false) {
|
||||
$this->fail('Job could not be reserved.');
|
||||
}
|
||||
$this->assertEquals('jobs', $job->queue);
|
||||
$this->assertEquals('Test_Job', $job->payload['class']);
|
||||
}
|
||||
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
if($job == false) {
|
||||
$this->fail('Job could not be reserved.');
|
||||
}
|
||||
$this->assertEquals('jobs', $job->queue);
|
||||
$this->assertEquals('Test_Job', $job->payload['class']);
|
||||
}
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testObjectArgumentsCannotBePassedToJob()
|
||||
{
|
||||
$args = new stdClass;
|
||||
$args->test = 'somevalue';
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testObjectArgumentsCannotBePassedToJob()
|
||||
{
|
||||
$args = new stdClass;
|
||||
$args->test = 'somevalue';
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
}
|
||||
public function testQueuedJobReturnsExactSamePassedInArguments()
|
||||
{
|
||||
$args = array(
|
||||
'int' => 123,
|
||||
'numArray' => array(
|
||||
1,
|
||||
2,
|
||||
),
|
||||
'assocArray' => array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
),
|
||||
);
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
|
||||
public function testQueuedJobReturnsExactSamePassedInArguments()
|
||||
{
|
||||
$args = array(
|
||||
'int' => 123,
|
||||
'numArray' => array(
|
||||
1,
|
||||
2,
|
||||
),
|
||||
'assocArray' => array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
),
|
||||
);
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals($args, $job->getArguments());
|
||||
}
|
||||
|
||||
$this->assertEquals($args, $job->getArguments());
|
||||
}
|
||||
public function testAfterJobIsReservedItIsRemoved()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Test_Job');
|
||||
Resque_Job::reserve('jobs');
|
||||
$this->assertFalse(Resque_Job::reserve('jobs'));
|
||||
}
|
||||
|
||||
public function testAfterJobIsReservedItIsRemoved()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Test_Job');
|
||||
Resque_Job::reserve('jobs');
|
||||
$this->assertFalse(Resque_Job::reserve('jobs'));
|
||||
}
|
||||
public function testRecreatedJobMatchesExistingJob()
|
||||
{
|
||||
$args = array(
|
||||
'int' => 123,
|
||||
'numArray' => array(
|
||||
1,
|
||||
2,
|
||||
),
|
||||
'assocArray' => array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
),
|
||||
);
|
||||
|
||||
public function testRecreatedJobMatchesExistingJob()
|
||||
{
|
||||
$args = array(
|
||||
'int' => 123,
|
||||
'numArray' => array(
|
||||
1,
|
||||
2,
|
||||
),
|
||||
'assocArray' => array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
),
|
||||
);
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
// Now recreate it
|
||||
$job->recreate();
|
||||
|
||||
// Now recreate it
|
||||
$job->recreate();
|
||||
|
||||
$newJob = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals($job->payload['class'], $newJob->payload['class']);
|
||||
$this->assertEquals($job->getArguments(), $newJob->getArguments());
|
||||
}
|
||||
$newJob = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals($job->payload['class'], $newJob->payload['class']);
|
||||
$this->assertEquals($job->getArguments(), $newJob->getArguments());
|
||||
}
|
||||
|
||||
|
||||
public function testFailedJobExceptionsAreCaught()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Failing_Job',
|
||||
'args' => null
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->worker = $this->worker;
|
||||
public function testFailedJobExceptionsAreCaught()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Failing_Job',
|
||||
'args' => null
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->worker = $this->worker;
|
||||
|
||||
$this->worker->perform($job);
|
||||
$this->worker->perform($job);
|
||||
|
||||
$this->assertEquals(1, Resque_Stat::get('failed'));
|
||||
$this->assertEquals(1, Resque_Stat::get('failed:'.$this->worker));
|
||||
}
|
||||
$this->assertEquals(1, Resque_Stat::get('failed'));
|
||||
$this->assertEquals(1, Resque_Stat::get('failed:' . $this->worker));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Resque_Exception
|
||||
*/
|
||||
public function testJobWithoutPerformMethodThrowsException()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Test_Job_Without_Perform_Method');
|
||||
$job = $this->worker->reserve();
|
||||
$job->worker = $this->worker;
|
||||
$job->perform();
|
||||
}
|
||||
/**
|
||||
* @expectedException Resque_Exception
|
||||
*/
|
||||
public function testJobWithoutPerformMethodThrowsException()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Test_Job_Without_Perform_Method');
|
||||
$job = $this->worker->reserve();
|
||||
$job->worker = $this->worker;
|
||||
$job->perform();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Resque_Exception
|
||||
*/
|
||||
public function testInvalidJobThrowsException()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Invalid_Job');
|
||||
$job = $this->worker->reserve();
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testJobWithTearDownCallbackFiresTearDown()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
/**
|
||||
* @expectedException Resque_Exception
|
||||
*/
|
||||
public function testInvalidJobThrowsException()
|
||||
{
|
||||
Resque::enqueue('jobs', 'Invalid_Job');
|
||||
$job = $this->worker->reserve();
|
||||
$job->worker = $this->worker;
|
||||
$job->perform();
|
||||
}
|
||||
|
||||
public function testNamespaceNaming() {
|
||||
$fixture = array(
|
||||
array('test' => 'more:than:one:with:', 'assertValue' => 'more:than:one:with:'),
|
||||
array('test' => 'more:than:one:without', 'assertValue' => 'more:than:one:without:'),
|
||||
array('test' => 'resque', 'assertValue' => 'resque:'),
|
||||
array('test' => 'resque:', 'assertValue' => 'resque:'),
|
||||
);
|
||||
public function testJobWithSetUpCallbackFiresSetUp()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Test_Job_With_SetUp',
|
||||
'args' => array(
|
||||
'somevar',
|
||||
'somevar2',
|
||||
),
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->perform();
|
||||
|
||||
foreach($fixture as $item) {
|
||||
Resque_Redis::prefix($item['test']);
|
||||
$this->assertEquals(Resque_Redis::getPrefix(), $item['assertValue']);
|
||||
}
|
||||
}
|
||||
$this->assertTrue(Test_Job_With_SetUp::$called);
|
||||
}
|
||||
|
||||
public function testJobWithNamespace()
|
||||
{
|
||||
Resque_Redis::prefix('php');
|
||||
$queue = 'jobs';
|
||||
$payload = array('another_value');
|
||||
Resque::enqueue($queue, 'Test_Job_With_TearDown', $payload);
|
||||
public function testJobWithTearDownCallbackFiresTearDown()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Test_Job_With_TearDown',
|
||||
'args' => array(
|
||||
'somevar',
|
||||
'somevar2',
|
||||
),
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->perform();
|
||||
|
||||
$this->assertEquals(Resque::queues(), array('jobs'));
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
$this->assertTrue(Test_Job_With_TearDown::$called);
|
||||
}
|
||||
|
||||
Resque_Redis::prefix('resque');
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
}
|
||||
public function testNamespaceNaming()
|
||||
{
|
||||
$fixture = array(
|
||||
array('test' => 'more:than:one:with:', 'assertValue' => 'more:than:one:with:'),
|
||||
array('test' => 'more:than:one:without', 'assertValue' => 'more:than:one:without:'),
|
||||
array('test' => 'resque', 'assertValue' => 'resque:'),
|
||||
array('test' => 'resque:', 'assertValue' => 'resque:'),
|
||||
);
|
||||
|
||||
public function testDequeueAll()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$this->assertEquals(Resque::dequeue($queue), 2);
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
}
|
||||
foreach ($fixture as $item) {
|
||||
Resque_Redis::prefix($item['test']);
|
||||
$this->assertEquals(Resque_Redis::getPrefix(), $item['assertValue']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDequeueMakeSureNotDeleteOthers()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$other_queue = 'other_jobs';
|
||||
Resque::enqueue($other_queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($other_queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$this->assertEquals(Resque::size($other_queue), 2);
|
||||
$this->assertEquals(Resque::dequeue($queue), 2);
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
$this->assertEquals(Resque::size($other_queue), 2);
|
||||
}
|
||||
public function testJobWithNamespace()
|
||||
{
|
||||
Resque_Redis::prefix('php');
|
||||
$queue = 'jobs';
|
||||
$payload = array('another_value');
|
||||
Resque::enqueue($queue, 'Test_Job_With_TearDown', $payload);
|
||||
|
||||
public function testDequeueSpecificItem()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue2');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
$this->assertEquals(Resque::queues(), array('jobs'));
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
|
||||
public function testDequeueSpecificMultipleItems()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue2', 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 2);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
Resque_Redis::prefix('resque');
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
}
|
||||
|
||||
public function testDequeueNonExistingItem()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue4');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
}
|
||||
public function testDequeueAll()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$this->assertEquals(Resque::dequeue($queue), 2);
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
}
|
||||
|
||||
public function testDequeueNonExistingItem2()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue4', 'Test_Job_Dequeue1');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
public function testDequeueMakeSureNotDeleteOthers()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$other_queue = 'other_jobs';
|
||||
Resque::enqueue($other_queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($other_queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$this->assertEquals(Resque::size($other_queue), 2);
|
||||
$this->assertEquals(Resque::dequeue($queue), 2);
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
$this->assertEquals(Resque::size($other_queue), 2);
|
||||
}
|
||||
|
||||
public function testDequeueItemID()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $qid);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
public function testDequeueSpecificItem()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue2');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
|
||||
public function testDequeueWrongItemID()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
#qid right but class name is wrong
|
||||
$test = array('Test_Job_Dequeue1' => $qid);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
public function testDequeueSpecificMultipleItems()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue2', 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 2);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
|
||||
public function testDequeueWrongItemID2()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => 'r4nD0mH4sh3dId');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
public function testDequeueNonExistingItem()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue4');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
}
|
||||
|
||||
public function testDequeueItemWithArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue9' => $arg);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
#$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
|
||||
public function testDequeueSeveralItemsWithArgs()
|
||||
{
|
||||
// GIVEN
|
||||
$queue = 'jobs';
|
||||
$args = array('foo' => 1, 'bar' => 10);
|
||||
$removeArgs = array('foo' => 1, 'bar' => 2);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $args);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $removeArgs);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $removeArgs);
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
|
||||
// WHEN
|
||||
$test = array('Test_Job_Dequeue9' => $removeArgs);
|
||||
$removedItems = Resque::dequeue($queue, $test);
|
||||
|
||||
// THEN
|
||||
$this->assertEquals($removedItems, 2);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
$item = Resque::pop($queue);
|
||||
$this->assertInternalType('array', $item['args']);
|
||||
$this->assertEquals(10, $item['args'][0]['bar'], 'Wrong items were dequeued from queue!');
|
||||
}
|
||||
public function testDequeueNonExistingItem2()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue4', 'Test_Job_Dequeue1');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
|
||||
public function testDequeueItemWithUnorderedArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
$arg2 = array('bar' => 2, 'foo' => 1);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $arg2);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
public function testDequeueItemID()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $qid);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
|
||||
public function testDequeueItemWithiWrongArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
$arg2 = array('foo' => 2, 'bar' => 3);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $arg2);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
public function testDequeueWrongItemID()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
#qid right but class name is wrong
|
||||
$test = array('Test_Job_Dequeue1' => $qid);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
|
||||
public function testUseDefaultFactoryToGetJobInstance()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => null
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Some_Job_Class', $instance);
|
||||
}
|
||||
public function testDequeueWrongItemID2()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => 'r4nD0mH4sh3dId');
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
|
||||
public function testUseFactoryToGetJobInstance()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => array(array())
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$factory = new Some_Stub_Factory();
|
||||
$job->setJobFactory($factory);
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||
}
|
||||
public function testDequeueItemWithArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue9' => $arg);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
#$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
|
||||
public function testDoNotUseFactoryToGetInstance()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => array(array())
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$factory = $this->getMock('Resque_Job_FactoryInterface');
|
||||
$testJob = $this->getMock('Resque_JobInterface');
|
||||
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||
}
|
||||
public function testDequeueSeveralItemsWithArgs()
|
||||
{
|
||||
// GIVEN
|
||||
$queue = 'jobs';
|
||||
$args = array('foo' => 1, 'bar' => 10);
|
||||
$removeArgs = array('foo' => 1, 'bar' => 2);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $args);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $removeArgs);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue9', $removeArgs);
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
|
||||
// WHEN
|
||||
$test = array('Test_Job_Dequeue9' => $removeArgs);
|
||||
$removedItems = Resque::dequeue($queue, $test);
|
||||
|
||||
// THEN
|
||||
$this->assertEquals($removedItems, 2);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
$item = Resque::pop($queue);
|
||||
$this->assertInternalType('array', $item['args']);
|
||||
$this->assertEquals(10, $item['args'][0]['bar'], 'Wrong items were dequeued from queue!');
|
||||
}
|
||||
|
||||
public function testDequeueItemWithUnorderedArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
$arg2 = array('bar' => 2, 'foo' => 1);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $arg2);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
|
||||
public function testDequeueItemWithiWrongArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
$arg2 = array('foo' => 2, 'bar' => 3);
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $arg2);
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
|
||||
public function testUseDefaultFactoryToGetJobInstance()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => null
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Some_Job_Class', $instance);
|
||||
}
|
||||
|
||||
public function testUseFactoryToGetJobInstance()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => array(array())
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$factory = new Some_Stub_Factory();
|
||||
$job->setJobFactory($factory);
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||
}
|
||||
|
||||
public function testDoNotUseFactoryToGetInstance()
|
||||
{
|
||||
$payload = array(
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => array(array())
|
||||
);
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$factory = $this->getMock('Resque_Job_FactoryInterface');
|
||||
$testJob = $this->getMock('Resque_JobInterface');
|
||||
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||
}
|
||||
}
|
||||
|
||||
class Some_Job_Class implements Resque_JobInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function perform()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function perform()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Some_Stub_Factory implements Resque_Job_FactoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $className
|
||||
* @param array $args
|
||||
* @param $queue
|
||||
* @return Resque_JobInterface
|
||||
*/
|
||||
public function create($className, $args, $queue)
|
||||
{
|
||||
return new Some_Job_Class();
|
||||
}
|
||||
/**
|
||||
* @param $className
|
||||
* @param array $args
|
||||
* @param $queue
|
||||
* @return Resque_JobInterface
|
||||
*/
|
||||
public function create($className, $args, $queue)
|
||||
{
|
||||
return new Some_Job_Class();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque_Log tests.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_LogTest extends Resque_Tests_TestCase
|
||||
{
|
||||
public function testLogInterpolate()
|
||||
{
|
||||
$logger = new Resque_Log();
|
||||
$actual = $logger->interpolate('string {replace}', array('replace' => 'value'));
|
||||
$expected = 'string value';
|
||||
public function testLogInterpolate()
|
||||
{
|
||||
$logger = new Resque_Log();
|
||||
$actual = $logger->interpolate('string {replace}', array('replace' => 'value'));
|
||||
$expected = 'string value';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testLogInterpolateMutiple()
|
||||
{
|
||||
$logger = new Resque_Log();
|
||||
$actual = $logger->interpolate(
|
||||
'string {replace1} {replace2}',
|
||||
array('replace1' => 'value1', 'replace2' => 'value2')
|
||||
);
|
||||
$expected = 'string value1 value2';
|
||||
public function testLogInterpolateMutiple()
|
||||
{
|
||||
$logger = new Resque_Log();
|
||||
$actual = $logger->interpolate(
|
||||
'string {replace1} {replace2}',
|
||||
array('replace1' => 'value1', 'replace2' => 'value2')
|
||||
);
|
||||
$expected = 'string value1 value2';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,197 +1,199 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque_Event tests.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException Resque_RedisException
|
||||
*/
|
||||
public function testRedisExceptionsAreSurfaced()
|
||||
{
|
||||
$mockCredis = $this->getMockBuilder('Credis_Client')
|
||||
->setMethods(['connect', '__call'])
|
||||
->getMock();
|
||||
$mockCredis->expects($this->any())->method('__call')
|
||||
->will($this->throwException(new CredisException('failure')));
|
||||
// public function testRedisExceptionsAreSurfaced()
|
||||
// {
|
||||
// $mockCredis = $this->getMockBuilder('Credis_Client')
|
||||
// ->setMethods(['connect', '__call'])
|
||||
// ->getMock();
|
||||
// $mockCredis->expects($this->any())->method('__call')
|
||||
// ->will($this->throwException(new CredisException('failure')));
|
||||
//
|
||||
// Resque::setBackend(function($database) use ($mockCredis) {
|
||||
// return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||
// });
|
||||
// Resque::redis()->ping();
|
||||
// }
|
||||
|
||||
Resque::setBackend(function($database) use ($mockCredis) {
|
||||
return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||
});
|
||||
Resque::redis()->ping();
|
||||
}
|
||||
/**
|
||||
* These DNS strings are considered valid.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validDsnStringProvider()
|
||||
{
|
||||
return [
|
||||
// Input , Expected output
|
||||
['', [
|
||||
'localhost',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['localhost', [
|
||||
'localhost',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['localhost:1234', [
|
||||
'localhost',
|
||||
1234,
|
||||
false,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['localhost:1234/2', [
|
||||
'localhost',
|
||||
1234,
|
||||
2,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['redis://foobar', [
|
||||
'foobar',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['redis://foobar/', [
|
||||
'foobar',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['redis://foobar:1234', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['redis://foobar:1234/15', [
|
||||
'foobar',
|
||||
1234,
|
||||
15,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['redis://foobar:1234/0', [
|
||||
'foobar',
|
||||
1234,
|
||||
0,
|
||||
false, false,
|
||||
[],
|
||||
]],
|
||||
['redis://user@foobar:1234', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', false,
|
||||
[],
|
||||
]],
|
||||
['redis://user@foobar:1234/15', [
|
||||
'foobar',
|
||||
1234,
|
||||
15,
|
||||
'user', false,
|
||||
[],
|
||||
]],
|
||||
['redis://user:pass@foobar:1234', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', 'pass',
|
||||
[],
|
||||
]],
|
||||
['redis://user:pass@foobar:1234?x=y&a=b', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', 'pass',
|
||||
['x' => 'y', 'a' => 'b'],
|
||||
]],
|
||||
['redis://:pass@foobar:1234?x=y&a=b', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
false, 'pass',
|
||||
['x' => 'y', 'a' => 'b'],
|
||||
]],
|
||||
['redis://user@foobar:1234?x=y&a=b', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', false,
|
||||
['x' => 'y', 'a' => 'b'],
|
||||
]],
|
||||
['redis://foobar:1234?x=y&a=b', [
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
false, false,
|
||||
['x' => 'y', 'a' => 'b'],
|
||||
]],
|
||||
['redis://user@foobar:1234/12?x=y&a=b', [
|
||||
'foobar',
|
||||
1234,
|
||||
12,
|
||||
'user', false,
|
||||
['x' => 'y', 'a' => 'b'],
|
||||
]],
|
||||
['tcp://user@foobar:1234/12?x=y&a=b', [
|
||||
'foobar',
|
||||
1234,
|
||||
12,
|
||||
'user', false,
|
||||
['x' => 'y', 'a' => 'b'],
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* These DNS strings are considered valid.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validDsnStringProvider()
|
||||
{
|
||||
return array(
|
||||
// Input , Expected output
|
||||
array('', array(
|
||||
'localhost',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('localhost', array(
|
||||
'localhost',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('localhost:1234', array(
|
||||
'localhost',
|
||||
1234,
|
||||
false,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('localhost:1234/2', array(
|
||||
'localhost',
|
||||
1234,
|
||||
2,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://foobar', array(
|
||||
'foobar',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://foobar/', array(
|
||||
'foobar',
|
||||
Resque_Redis::DEFAULT_PORT,
|
||||
false,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://foobar:1234', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://foobar:1234/15', array(
|
||||
'foobar',
|
||||
1234,
|
||||
15,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://foobar:1234/0', array(
|
||||
'foobar',
|
||||
1234,
|
||||
0,
|
||||
false, false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://user@foobar:1234', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://user@foobar:1234/15', array(
|
||||
'foobar',
|
||||
1234,
|
||||
15,
|
||||
'user', false,
|
||||
array(),
|
||||
)),
|
||||
array('redis://user:pass@foobar:1234', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', 'pass',
|
||||
array(),
|
||||
)),
|
||||
array('redis://user:pass@foobar:1234?x=y&a=b', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', 'pass',
|
||||
array('x' => 'y', 'a' => 'b'),
|
||||
)),
|
||||
array('redis://:pass@foobar:1234?x=y&a=b', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
false, 'pass',
|
||||
array('x' => 'y', 'a' => 'b'),
|
||||
)),
|
||||
array('redis://user@foobar:1234?x=y&a=b', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
'user', false,
|
||||
array('x' => 'y', 'a' => 'b'),
|
||||
)),
|
||||
array('redis://foobar:1234?x=y&a=b', array(
|
||||
'foobar',
|
||||
1234,
|
||||
false,
|
||||
false, false,
|
||||
array('x' => 'y', 'a' => 'b'),
|
||||
)),
|
||||
array('redis://user@foobar:1234/12?x=y&a=b', array(
|
||||
'foobar',
|
||||
1234,
|
||||
12,
|
||||
'user', false,
|
||||
array('x' => 'y', 'a' => 'b'),
|
||||
)),
|
||||
array('tcp://user@foobar:1234/12?x=y&a=b', array(
|
||||
'foobar',
|
||||
1234,
|
||||
12,
|
||||
'user', false,
|
||||
array('x' => 'y', 'a' => 'b'),
|
||||
)),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* These DSN values should throw exceptions
|
||||
* @return array
|
||||
*/
|
||||
public function bogusDsnStringProvider()
|
||||
{
|
||||
return [
|
||||
['http://foo.bar/'],
|
||||
['user:@foobar:1234?x=y&a=b'],
|
||||
['foobar:1234?x=y&a=b'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* These DSN values should throw exceptions
|
||||
* @return array
|
||||
*/
|
||||
public function bogusDsnStringProvider()
|
||||
{
|
||||
return array(
|
||||
array('http://foo.bar/'),
|
||||
array('user:@foobar:1234?x=y&a=b'),
|
||||
array('foobar:1234?x=y&a=b'),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @dataProvider validDsnStringProvider
|
||||
*/
|
||||
public function testParsingValidDsnString($dsn, $expected)
|
||||
{
|
||||
$result = Resque_Redis::parseDsn($dsn);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDsnStringProvider
|
||||
*/
|
||||
public function testParsingValidDsnString($dsn, $expected)
|
||||
{
|
||||
$result = Resque_Redis::parseDsn($dsn);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider bogusDsnStringProvider
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testParsingBogusDsnStringThrowsException($dsn)
|
||||
{
|
||||
// The next line should throw an InvalidArgumentException
|
||||
$result = Resque_Redis::parseDsn($dsn);
|
||||
}
|
||||
/**
|
||||
* @dataProvider bogusDsnStringProvider
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testParsingBogusDsnStringThrowsException($dsn)
|
||||
{
|
||||
// The next line should throw an InvalidArgumentException
|
||||
Resque_Redis::parseDsn($dsn);
|
||||
}
|
||||
}
|
|
@ -1,49 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque_Stat tests.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_StatTest extends Resque_Tests_TestCase
|
||||
{
|
||||
public function testStatCanBeIncremented()
|
||||
{
|
||||
Resque_Stat::incr('test_incr');
|
||||
Resque_Stat::incr('test_incr');
|
||||
$this->assertEquals(2, $this->redis->get('resque:stat:test_incr'));
|
||||
}
|
||||
public function testStatCanBeIncremented()
|
||||
{
|
||||
Resque_Stat::incr('test_incr');
|
||||
Resque_Stat::incr('test_incr');
|
||||
$this->assertEquals(2, $this->redis->get('resque:stat:test_incr'));
|
||||
}
|
||||
|
||||
public function testStatCanBeIncrementedByX()
|
||||
{
|
||||
Resque_Stat::incr('test_incrX', 10);
|
||||
Resque_Stat::incr('test_incrX', 11);
|
||||
$this->assertEquals(21, $this->redis->get('resque:stat:test_incrX'));
|
||||
}
|
||||
public function testStatCanBeIncrementedByX()
|
||||
{
|
||||
Resque_Stat::incr('test_incrX', 10);
|
||||
Resque_Stat::incr('test_incrX', 11);
|
||||
$this->assertEquals(21, $this->redis->get('resque:stat:test_incrX'));
|
||||
}
|
||||
|
||||
public function testStatCanBeDecremented()
|
||||
{
|
||||
Resque_Stat::incr('test_decr', 22);
|
||||
Resque_Stat::decr('test_decr');
|
||||
$this->assertEquals(21, $this->redis->get('resque:stat:test_decr'));
|
||||
}
|
||||
public function testStatCanBeDecremented()
|
||||
{
|
||||
Resque_Stat::incr('test_decr', 22);
|
||||
Resque_Stat::decr('test_decr');
|
||||
$this->assertEquals(21, $this->redis->get('resque:stat:test_decr'));
|
||||
}
|
||||
|
||||
public function testStatCanBeDecrementedByX()
|
||||
{
|
||||
Resque_Stat::incr('test_decrX', 22);
|
||||
Resque_Stat::decr('test_decrX', 11);
|
||||
$this->assertEquals(11, $this->redis->get('resque:stat:test_decrX'));
|
||||
}
|
||||
public function testStatCanBeDecrementedByX()
|
||||
{
|
||||
Resque_Stat::incr('test_decrX', 22);
|
||||
Resque_Stat::decr('test_decrX', 11);
|
||||
$this->assertEquals(11, $this->redis->get('resque:stat:test_decrX'));
|
||||
}
|
||||
|
||||
public function testGetStatByName()
|
||||
{
|
||||
Resque_Stat::incr('test_get', 100);
|
||||
$this->assertEquals(100, Resque_Stat::get('test_get'));
|
||||
}
|
||||
public function testGetStatByName()
|
||||
{
|
||||
Resque_Stat::incr('test_get', 100);
|
||||
$this->assertEquals(100, Resque_Stat::get('test_get'));
|
||||
}
|
||||
|
||||
public function testGetUnknownStatReturns0()
|
||||
{
|
||||
$this->assertEquals(0, Resque_Stat::get('test_get_unknown'));
|
||||
}
|
||||
public function testGetUnknownStatReturns0()
|
||||
{
|
||||
$this->assertEquals(0, Resque_Stat::get('test_get_unknown'));
|
||||
}
|
||||
}
|
|
@ -1,30 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque test case class. Contains setup and teardown methods.
|
||||
*
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @package Resque/Tests
|
||||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
|
||||
|
||||
class Resque_Tests_TestCase extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $resque;
|
||||
protected $redis;
|
||||
protected $resque;
|
||||
protected $redis;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$config = file_get_contents(REDIS_CONF);
|
||||
preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches);
|
||||
$this->redis = new Credis_Client('localhost', $matches[1]);
|
||||
public function setUp()
|
||||
{
|
||||
// $config = file_get_contents(REDIS_CONF);
|
||||
// preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches);
|
||||
$this->redis = new \Redis();
|
||||
$this->redis->connect('localhost');
|
||||
$this->redis->select(9);
|
||||
|
||||
Resque::setBackend('redis://localhost:' . $matches[1]);
|
||||
Resque::setBackend('localhost', 9);
|
||||
|
||||
// Flush redis
|
||||
$this->redis->flushAll();
|
||||
}
|
||||
// Flush redis
|
||||
$this->redis->flushAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Resque_Worker tests.
|
||||
*
|
||||
|
@ -6,6 +7,7 @@
|
|||
* @author Chris Boulton <chris@bigcommerce.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
{
|
||||
public function testWorkerRegistersInList()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue