|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the tarantool/queue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Tarantool\Queue\Tests\Unit; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Tarantool\Queue\States; |
|
18
|
|
|
use Tarantool\Queue\Task; |
|
19
|
|
|
|
|
20
|
|
|
final class TaskTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider provideTuples |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testCreateFromTuple(array $tuple) : void |
|
26
|
|
|
{ |
|
27
|
|
|
$task = Task::fromTuple($tuple); |
|
28
|
|
|
|
|
29
|
|
|
self::assertSame($tuple[0], $task->getId()); |
|
30
|
|
|
self::assertSame($tuple[1], $task->getState()); |
|
31
|
|
|
|
|
32
|
|
|
if (3 === \count($tuple)) { |
|
33
|
|
|
self::assertSame($tuple[2], $task->getData()); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function provideTuples() : iterable |
|
38
|
|
|
{ |
|
39
|
|
|
return [ |
|
40
|
|
|
[[0, States::READY, [42]]], |
|
41
|
|
|
[[1, States::DONE, null]], |
|
42
|
|
|
[[2, States::BURIED]], |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @dataProvider provideStates |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testIsser(string $state) : void |
|
50
|
|
|
{ |
|
51
|
|
|
static $map = [ |
|
52
|
|
|
States::READY => 'isReady', |
|
53
|
|
|
States::TAKEN => 'isTaken', |
|
54
|
|
|
States::DONE => 'isDone', |
|
55
|
|
|
States::BURIED => 'isBuried', |
|
56
|
|
|
States::DELAYED => 'isDelayed', |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
$task = Task::fromTuple([0, $state, null]); |
|
60
|
|
|
|
|
61
|
|
|
self::assertTrue($task->{$map[$state]}()); |
|
62
|
|
|
|
|
63
|
|
|
$issers = $map; |
|
64
|
|
|
unset($issers[$state]); |
|
65
|
|
|
|
|
66
|
|
|
foreach ($issers as $isser) { |
|
67
|
|
|
self::assertFalse($task->$isser()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function provideStates() : iterable |
|
72
|
|
|
{ |
|
73
|
|
|
return [ |
|
74
|
|
|
[States::READY], |
|
75
|
|
|
[States::TAKEN], |
|
76
|
|
|
[States::DONE], |
|
77
|
|
|
[States::BURIED], |
|
78
|
|
|
[States::DELAYED], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|