Add basic unit tests for Queue class using Dummy driver

This commit is contained in:
Kijin Sung 2024-10-11 23:19:53 +09:00
parent b4e7d4aaad
commit 4b0b485a13
2 changed files with 36 additions and 1 deletions

View file

@ -9,6 +9,11 @@ use Rhymix\Framework\Drivers\QueueInterface;
*/
class Dummy implements QueueInterface
{
/**
* Dummy queue for testing.
*/
protected $_dummy_queue;
/**
* Create a new instance of the current Queue driver, using the given settings.
*
@ -80,6 +85,11 @@ class Dummy implements QueueInterface
*/
public function addTask(string $handler, ?object $args = null, ?object $options = null): int
{
$this->_dummy_queue = (object)[
'handler' => $handler,
'args' => $args,
'options' => $options,
];
return 0;
}
@ -91,6 +101,8 @@ class Dummy implements QueueInterface
*/
public function getTask(int $blocking = 0): ?object
{
return null;
$result = $this->_dummy_queue;
$this->_dummy_queue = null;
return $result;
}
}

View file

@ -0,0 +1,23 @@
<?php
class QueueTest extends \Codeception\Test\Unit
{
public function testDummyQueue()
{
config('queue.driver', 'dummy');
$handler = 'myfunc';
$args = (object)['foo' => 'bar'];
$options = (object)['key' => 'val'];
Rhymix\Framework\Queue::addTask($handler, $args, $options);
$output = Rhymix\Framework\Queue::getTask();
$this->assertEquals('myfunc', $output->handler);
$this->assertEquals('bar', $output->args->foo);
$this->assertEquals('val', $output->options->key);
$output = Rhymix\Framework\Queue::getTask();
$this->assertNull($output);
}
}