forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectorTest.php
More file actions
44 lines (38 loc) · 1.63 KB
/
SelectorTest.php
File metadata and controls
44 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Deployer\Selector;
use Deployer\Deployer;
use Deployer\Host\Host;
use Deployer\Host\HostCollection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
class SelectorTest extends TestCase
{
protected function setUp(): void
{
new Deployer(new Application());
}
protected function tearDown(): void
{
Deployer::resetInstance();
}
public function testSelectHosts()
{
$prod = (new Host('prod.domain.com'))->set('labels', ['stage' => 'prod']);
$front = (new Host('prod.domain.com/front'))->set('labels', ['stage' => 'prod', 'tier' => 'frontend']);
$beta = (new Host('beta.domain.com'))->set('labels', ['stage' => 'beta']);
$dev = (new Host('dev'))->set('labels', ['stage' => 'dev']);
$multi = (new Host('multi'))->set('labels', ['stage' => ['prod', 'beta']]);
$allHosts = [$prod, $front, $beta, $dev, $multi];
$hosts = new HostCollection();
foreach ($allHosts as $host) {
$hosts->set($host->getAlias(), $host);
}
$selector = new Selector($hosts);
self::assertEquals($allHosts, $selector->select('all'));
self::assertEquals([$prod, $front, $multi], $selector->select('stage=prod'));
self::assertEquals([$front], $selector->select('stage=prod & tier=frontend'));
self::assertEquals([$front, $beta, $multi], $selector->select('prod.domain.com/front, stage=beta'));
self::assertEquals([$prod, $beta, $dev, $multi], $selector->select('all & tier != frontend'));
self::assertEquals([$prod, $front, $dev], $selector->select('stage != beta'));
}
}