mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-10 04:24:14 +09:00
Add basic unit tests for Queue class using Dummy driver
This commit is contained in:
parent
b4e7d4aaad
commit
4b0b485a13
2 changed files with 36 additions and 1 deletions
|
|
@ -9,6 +9,11 @@ use Rhymix\Framework\Drivers\QueueInterface;
|
||||||
*/
|
*/
|
||||||
class Dummy implements 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.
|
* 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
|
public function addTask(string $handler, ?object $args = null, ?object $options = null): int
|
||||||
{
|
{
|
||||||
|
$this->_dummy_queue = (object)[
|
||||||
|
'handler' => $handler,
|
||||||
|
'args' => $args,
|
||||||
|
'options' => $options,
|
||||||
|
];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,6 +101,8 @@ class Dummy implements QueueInterface
|
||||||
*/
|
*/
|
||||||
public function getTask(int $blocking = 0): ?object
|
public function getTask(int $blocking = 0): ?object
|
||||||
{
|
{
|
||||||
return null;
|
$result = $this->_dummy_queue;
|
||||||
|
$this->_dummy_queue = null;
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
tests/unit/framework/QueueTest.php
Normal file
23
tests/unit/framework/QueueTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue