Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up unit test output #55

Merged
merged 3 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit
tools: phpunit:5
extensions: redis

- name: Setup problem matchers for PHP
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>

<testsuites>
<testsuite name="Resque Test Suite">
<directory>./test/Resque/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">./lib/Resque/</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
</phpunit>
15 changes: 14 additions & 1 deletion test/Resque/Tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ public function setUp()
{
Test_Job::$called = false;

$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')
->getMock();

// Register a worker to test with
$this->worker = new Resque_Worker('jobs');
$this->worker->setLogger(new Resque_Log());
$this->worker->setLogger($this->logger);
$this->worker->registerWorker();
}

Expand Down Expand Up @@ -56,6 +59,15 @@ public function testEventCallbacksFire($event, $callback)
Resque_Event::listen($event, array($this, $callback));

$job = $this->getEventTestJob();

$this->logger->expects($this->exactly(3))
->method('log')
->withConsecutive(
[ 'notice', '{job} has finished', [ 'job' => $job ] ],
[ 'debug', 'Registered signals', [] ],
[ 'info', 'Checking {queue} for jobs', [ 'queue' => 'jobs' ] ]
);

$this->worker->perform($job);
$this->worker->work(0);

Expand All @@ -72,6 +84,7 @@ public function testBeforeForkEventCallbackFires()
'somevar'
));
$job = $this->getEventTestJob();

$this->worker->work(0);
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
}
Expand Down
5 changes: 4 additions & 1 deletion test/Resque/Tests/JobPIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ public function setUp()

// Register a worker to test with
$this->worker = new Resque_Worker('jobs');
$this->worker->setLogger(new Resque_Log());
$this->worker->setLogger($this->logger);
}

public function testQueuedJobDoesNotReturnPID()
{
$this->logger->expects($this->never())
->method('log');

$token = Resque::enqueue('jobs', 'Test_Job', null, true);
$this->assertEquals(0, Resque_Job_PID::get($token));
}
Expand Down
4 changes: 2 additions & 2 deletions test/Resque/Tests/JobStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function setUp()

// Register a worker to test with
$this->worker = new Resque_Worker('jobs');
$this->worker->setLogger(new Resque_Log());
$this->worker->setLogger($this->logger);
}

public function testJobStatusCanBeTracked()
Expand Down Expand Up @@ -103,4 +103,4 @@ public function testRecreatedJobWithTrackingStillTracksStatus()
$newJob = Resque_Job::reserve('jobs');
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $newJob->getStatus());
}
}
}
22 changes: 12 additions & 10 deletions test/Resque/Tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setUp()

// Register a worker to test with
$this->worker = new Resque_Worker('jobs');
$this->worker->setLogger(new Resque_Log());
$this->worker->setLogger($this->logger);
$this->worker->registerWorker();
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public function testInvalidJobThrowsException()
$job->worker = $this->worker;
$job->perform();
}

public function testJobWithSetUpCallbackFiresSetUp()
{
$payload = array(
Expand All @@ -165,10 +165,10 @@ public function testJobWithSetUpCallbackFiresSetUp()
);
$job = new Resque_Job('jobs', $payload);
$job->perform();

$this->assertTrue(Test_Job_With_SetUp::$called);
}

public function testJobWithTearDownCallbackFiresTearDown()
{
$payload = array(
Expand All @@ -180,7 +180,7 @@ public function testJobWithTearDownCallbackFiresTearDown()
);
$job = new Resque_Job('jobs', $payload);
$job->perform();

$this->assertTrue(Test_Job_With_TearDown::$called);
}

Expand Down Expand Up @@ -329,7 +329,7 @@ public function testDequeueItemWithArg()
$this->assertEquals(Resque::dequeue($queue, $test), 1);
#$this->assertEquals(Resque::size($queue), 1);
}

public function testDequeueSeveralItemsWithArgs()
{
// GIVEN
Expand All @@ -340,11 +340,11 @@ public function testDequeueSeveralItemsWithArgs()
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);
Expand Down Expand Up @@ -410,8 +410,10 @@ public function testDoNotUseFactoryToGetInstance()
'args' => array(array())
);
$job = new Resque_Job('jobs', $payload);
$factory = $this->getMock('Resque_Job_FactoryInterface');
$testJob = $this->getMock('Resque_JobInterface');
$factory = $this->getMockBuilder('Resque_Job_FactoryInterface')
->getMock();
$testJob = $this->getMockBuilder('Resque_JobInterface')
->getMock();
$factory->expects(self::never())->method('create')->will(self::returnValue($testJob));
$instance = $job->getInstance();
$this->assertInstanceOf('Resque_JobInterface', $instance);
Expand Down
4 changes: 4 additions & 0 deletions test/Resque/Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
{
protected $resque;
protected $redis;
protected $logger;

public static function setUpBeforeClass()
{
Expand All @@ -22,6 +23,9 @@ public function setUp()
preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches);
$this->redis = new Credis_Client('localhost', $matches[1]);

$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')
->getMock();

Resque::setBackend('redis://localhost:' . $matches[1]);

// Flush redis
Expand Down
44 changes: 22 additions & 22 deletions test/Resque/Tests/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
public function testWorkerRegistersInList()
{
$worker = new Resque_Worker('*');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

// Make sure the worker is in the list
Expand All @@ -24,7 +24,7 @@ public function testGetAllWorkers()
// Register a few workers
for($i = 0; $i < $num; ++$i) {
$worker = new Resque_Worker('queue_' . $i);
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();
}

Expand All @@ -35,7 +35,7 @@ public function testGetAllWorkers()
public function testGetWorkerById()
{
$worker = new Resque_Worker('*');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

$newWorker = Resque_Worker::find((string)$worker);
Expand All @@ -50,7 +50,7 @@ public function testInvalidWorkerDoesNotExist()
public function testWorkerCanUnregister()
{
$worker = new Resque_Worker('*');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();
$worker->unregisterWorker();

Expand All @@ -62,7 +62,7 @@ public function testWorkerCanUnregister()
public function testPausedWorkerDoesNotPickUpJobs()
{
$worker = new Resque_Worker('*');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->pauseProcessing();
Resque::enqueue('jobs', 'Test_Job');
$worker->work(0);
Expand All @@ -73,7 +73,7 @@ public function testPausedWorkerDoesNotPickUpJobs()
public function testResumedWorkerPicksUpJobs()
{
$worker = new Resque_Worker('*');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->pauseProcessing();
Resque::enqueue('jobs', 'Test_Job');
$worker->work(0);
Expand All @@ -89,7 +89,7 @@ public function testWorkerCanWorkOverMultipleQueues()
'queue1',
'queue2'
));
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();
Resque::enqueue('queue1', 'Test_Job_1');
Resque::enqueue('queue2', 'Test_Job_2');
Expand All @@ -108,7 +108,7 @@ public function testWorkerWorksQueuesInSpecifiedOrder()
'medium',
'low'
));
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

// Queue the jobs in a different order
Expand All @@ -130,7 +130,7 @@ public function testWorkerWorksQueuesInSpecifiedOrder()
public function testWildcardQueueWorkerWorksAllQueues()
{
$worker = new Resque_Worker('*');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

Resque::enqueue('queue1', 'Test_Job_1');
Expand All @@ -146,7 +146,7 @@ public function testWildcardQueueWorkerWorksAllQueues()
public function testWorkerDoesNotWorkOnUnknownQueues()
{
$worker = new Resque_Worker('queue1');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();
Resque::enqueue('queue2', 'Test_Job');

Expand All @@ -157,7 +157,7 @@ public function testWorkerClearsItsStatusWhenNotWorking()
{
Resque::enqueue('jobs', 'Test_Job');
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$job = $worker->reserve();
$worker->workingOn($job);
$worker->doneWorking();
Expand All @@ -167,7 +167,7 @@ public function testWorkerClearsItsStatusWhenNotWorking()
public function testWorkerRecordsWhatItIsWorkingOn()
{
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

$payload = array(
Expand All @@ -190,7 +190,7 @@ public function testWorkerErasesItsStatsWhenShutdown()
Resque::enqueue('jobs', 'Invalid_Job');

$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->work(0);
$worker->work(0);

Expand All @@ -202,18 +202,18 @@ public function testWorkerCleansUpDeadWorkersOnStartup()
{
// Register a good worker
$goodWorker = new Resque_Worker('jobs');
$goodWorker->setLogger(new Resque_Log());
$goodWorker->setLogger($this->logger);
$goodWorker->registerWorker();
$workerId = explode(':', $goodWorker);

// Register some bad workers
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->setId($workerId[0].':1:jobs');
$worker->registerWorker();

$worker = new Resque_Worker(array('high', 'low'));
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->setId($workerId[0].':2:high,low');
$worker->registerWorker();

Expand All @@ -229,14 +229,14 @@ public function testDeadWorkerCleanUpDoesNotCleanUnknownWorkers()
{
// Register a bad worker on this machine
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$workerId = explode(':', $worker);
$worker->setId($workerId[0].':1:jobs');
$worker->registerWorker();

// Register some other false workers
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->setId('my.other.host:1:jobs');
$worker->registerWorker();

Expand All @@ -253,7 +253,7 @@ public function testDeadWorkerCleanUpDoesNotCleanUnknownWorkers()
public function testWorkerFailsUncompletedJobsOnExit()
{
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

$payload = array(
Expand All @@ -270,7 +270,7 @@ public function testWorkerFailsUncompletedJobsOnExit()
public function testBlockingListPop()
{
$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->registerWorker();

Resque::enqueue('jobs', 'Test_Job_1');
Expand All @@ -296,9 +296,9 @@ public function testWorkerFailsSegmentationFaultJob()
Resque::enqueue('jobs', 'Test_Infinite_Recursion_Job');

$worker = new Resque_Worker('jobs');
$worker->setLogger(new Resque_Log());
$worker->setLogger($this->logger);
$worker->work(0);

$this->assertEquals(1, Resque_Stat::get('failed'));
}
}
}