1 | <?php |
||||||
2 | /* (c) Anton Medvedev <[email protected]> |
||||||
3 | * |
||||||
4 | * For the full copyright and license information, please view the LICENSE |
||||||
5 | * file that was distributed with this source code. |
||||||
6 | */ |
||||||
7 | |||||||
8 | namespace Deployer\Task; |
||||||
9 | |||||||
10 | use PHPUnit\Framework\TestCase; |
||||||
11 | |||||||
12 | class ScriptManagerTest extends TestCase |
||||||
13 | { |
||||||
14 | public function testGetTasks() |
||||||
15 | { |
||||||
16 | $notify = new Task('notify'); |
||||||
17 | $info = new GroupTask('info', ['notify']); |
||||||
18 | $deploy = new GroupTask('deploy', ['deploy:setup', 'deploy:release']); |
||||||
19 | $deploy->addBefore($info); |
||||||
20 | $setup = new Task('deploy:setup'); |
||||||
21 | $release = new Task('deploy:release'); |
||||||
22 | |||||||
23 | $taskCollection = new TaskCollection(); |
||||||
24 | $taskCollection->set($notify->getName(), $notify); |
||||||
25 | $taskCollection->set($info->getName(), $info); |
||||||
26 | $taskCollection->set($deploy->getName(), $deploy); |
||||||
27 | $taskCollection->set($setup->getName(), $setup); |
||||||
28 | $taskCollection->set($release->getName(), $release); |
||||||
29 | |||||||
30 | $scriptManager = new ScriptManager($taskCollection); |
||||||
31 | self::assertEquals([$notify, $setup, $release], $scriptManager->getTasks('deploy')); |
||||||
32 | } |
||||||
33 | |||||||
34 | public function testOnce() |
||||||
35 | { |
||||||
36 | $a = new Task('a'); |
||||||
37 | $b = new Task('b'); |
||||||
38 | $b->once(); |
||||||
39 | $group = new GroupTask('group', ['a', 'b']); |
||||||
40 | |||||||
41 | $taskCollection = new TaskCollection(); |
||||||
42 | $taskCollection->add($a); |
||||||
43 | $taskCollection->add($b); |
||||||
44 | $taskCollection->add($group); |
||||||
45 | |||||||
46 | $scriptManager = new ScriptManager($taskCollection); |
||||||
47 | self::assertEquals([$a, $b], $scriptManager->getTasks('group')); |
||||||
48 | self::assertFalse($a->isOnce()); |
||||||
49 | self::assertTrue($b->isOnce()); |
||||||
50 | |||||||
51 | $group->once(); |
||||||
52 | self::assertEquals([$a, $b], $scriptManager->getTasks('group')); |
||||||
53 | self::assertTrue($a->isOnce()); |
||||||
54 | self::assertTrue($b->isOnce()); |
||||||
55 | } |
||||||
56 | |||||||
57 | public function testSelectsCombine() |
||||||
58 | { |
||||||
59 | $a = new Task('a'); |
||||||
60 | $b = new Task('b'); |
||||||
61 | $c = new Task('c'); |
||||||
62 | $b->select('stage=beta'); |
||||||
63 | $c->select('stage=alpha|beta & role=db'); |
||||||
64 | $group = new GroupTask('group', ['a', 'b', 'c']); |
||||||
65 | |||||||
66 | $taskCollection = new TaskCollection(); |
||||||
67 | $taskCollection->add($a); |
||||||
68 | $taskCollection->add($b); |
||||||
69 | $taskCollection->add($c); |
||||||
70 | $taskCollection->add($group); |
||||||
71 | |||||||
72 | $scriptManager = new ScriptManager($taskCollection); |
||||||
73 | self::assertEquals([$a, $b, $c], $scriptManager->getTasks('group')); |
||||||
74 | self::assertNull($a->getSelector()); |
||||||
75 | self::assertEquals([[['=', 'stage', ['beta']]]], $b->getSelector()); |
||||||
76 | self::assertEquals([[['=', 'stage', ['alpha', 'beta']],['=', 'role', ['db']]]], $c->getSelector()); |
||||||
77 | |||||||
78 | $group->select('role=prod'); |
||||||
79 | self::assertEquals([$a, $b, $c], $scriptManager->getTasks('group')); |
||||||
80 | self::assertEquals([[['=', 'role', ['prod']]]], $a->getSelector()); |
||||||
81 | self::assertEquals([[['=', 'stage', ['beta']]],[['=', 'role', ['prod']]]], $b->getSelector()); |
||||||
82 | self::assertEquals([[['=', 'stage', ['alpha', 'beta']],['=', 'role', ['db']]],[['=', 'role', ['prod']]]], $c->getSelector()); |
||||||
83 | } |
||||||
84 | |||||||
85 | public function testThrowsExceptionIfTaskCollectionEmpty() |
||||||
86 | { |
||||||
87 | self::expectException(\InvalidArgumentException::class); |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
88 | |||||||
89 | $scriptManager = new ScriptManager(new TaskCollection()); |
||||||
90 | $scriptManager->getTasks(''); |
||||||
91 | } |
||||||
92 | |||||||
93 | public function testThrowsExceptionIfTaskDontExists() |
||||||
94 | { |
||||||
95 | self::expectException(\InvalidArgumentException::class); |
||||||
0 ignored issues
–
show
The method
PHPUnit\Framework\TestCase::expectException() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
96 | |||||||
97 | $taskCollection = new TaskCollection(); |
||||||
98 | $taskCollection->set('testTask', new Task('testTask')); |
||||||
99 | |||||||
100 | $scriptManager = new ScriptManager($taskCollection); |
||||||
101 | $scriptManager->getTasks('testTask2'); |
||||||
102 | } |
||||||
103 | } |
||||||
104 |