TaskTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 28
c 3
b 0
f 0
dl 0
loc 59
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A provideStates() 0 8 1
A testIsser() 0 19 2
A testCreateFromTuple() 0 9 2
A provideTuples() 0 6 1
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