-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathServerRepositoryTest.php
More file actions
65 lines (54 loc) · 2.16 KB
/
Copy pathServerRepositoryTest.php
File metadata and controls
65 lines (54 loc) · 2.16 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
* This file is part of the EasyDeploy project.
*
* (c) Javier Eguiluz <javier.eguiluz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EasyCorp\Bundle\EasyDeployBundle\EasyDeployBundle\Tests;
use EasyCorp\Bundle\EasyDeployBundle\Server\Server;
use EasyCorp\Bundle\EasyDeployBundle\Server\ServerRepository;
use PHPUnit\Framework\TestCase;
class ServerRepositoryTest extends TestCase
{
/** @var ServerRepository */
private $servers;
protected function setUp(): void
{
$repository = new ServerRepository();
$repository->add(new Server('host0'));
$repository->add(new Server('host1', []));
$repository->add(new Server('host2', ['app']));
$repository->add(new Server('host3', ['workers', 'worker1']));
$repository->add(new Server('host4', ['workers', 'worker2']));
$repository->add(new Server('host5', ['database']));
$this->servers = $repository;
}
public function test_find_all()
{
$servers = $this->servers->findAll();
$serverNames = array_values(array_map(function ($v) { return (string) $v; }, $servers));
$this->assertSame(['host0', 'host1', 'host2', 'host3', 'host4', 'host5'], $serverNames);
}
/** @dataProvider findByRolesProvider */
public function test_find_by_roles(array $roles, array $expectedResult)
{
$servers = $this->servers->findByRoles($roles);
// array_values() is needed to reset the values of the keys
$serverNames = array_values(array_map(function ($v) { return (string) $v; }, $servers));
$this->assertSame($expectedResult, $serverNames);
}
public function findByRolesProvider()
{
yield [[], []];
yield [['app'], ['host0', 'host2']];
yield [['workers'], ['host3', 'host4']];
yield [['worker1'], ['host3']];
yield [['worker2'], ['host4']];
yield [['database'], ['host5']];
yield [['database', 'workers'], ['host3', 'host4', 'host5']];
yield [['app', 'database', 'worker1'], ['host0', 'host2', 'host3', 'host5']];
}
}