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\Host; |
||
9 | |||
10 | use Deployer\Configuration; |
||
11 | use PHPUnit\Framework\TestCase; |
||
12 | |||
13 | class HostTest extends TestCase |
||
14 | { |
||
15 | public function testHost() |
||
16 | { |
||
17 | $host = new Host('host'); |
||
18 | $host |
||
19 | ->setHostname('hostname') |
||
20 | ->setRemoteUser('remote_user') |
||
21 | ->setPort(22) |
||
22 | ->setConfigFile('~/.ssh/config') |
||
23 | ->setIdentityFile('~/.ssh/id_rsa') |
||
24 | ->setForwardAgent(true) |
||
25 | ->setSshMultiplexing(true); |
||
26 | |||
27 | self::assertEquals('host', $host->getAlias()); |
||
28 | self::assertStringContainsString('host', $host->getTag()); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
29 | self::assertEquals('hostname', $host->getHostname()); |
||
30 | self::assertEquals('remote_user', $host->getRemoteUser()); |
||
31 | self::assertEquals(22, $host->getPort()); |
||
32 | self::assertEquals('~/.ssh/config', $host->getConfigFile()); |
||
33 | self::assertEquals('~/.ssh/id_rsa', $host->getIdentityFile()); |
||
34 | self::assertEquals(true, $host->getForwardAgent()); |
||
35 | self::assertEquals(true, $host->getSshMultiplexing()); |
||
36 | } |
||
37 | |||
38 | public function testConfigurationAccessor() |
||
39 | { |
||
40 | $host = new Host('host'); |
||
41 | $host |
||
42 | ->set('roles', ['db', 'app']) |
||
43 | ->set('key', 'value') |
||
44 | ->set('array', [1]) |
||
45 | ->add('array', [2]); |
||
46 | |||
47 | self::assertEquals(['db', 'app'], $host->get('roles')); |
||
48 | self::assertEquals('value', $host->get('key')); |
||
49 | self::assertEquals([1, 2], $host->get('array')); |
||
50 | } |
||
51 | |||
52 | public function testHostAlias() |
||
53 | { |
||
54 | $host = new Host('host/alias'); |
||
55 | self::assertEquals('host/alias', $host->getAlias()); |
||
56 | self::assertEquals('host', $host->getHostname()); |
||
57 | } |
||
58 | |||
59 | public function testHostWithParams() |
||
60 | { |
||
61 | $host = new Host('host'); |
||
62 | $value = 'new_value'; |
||
63 | $host |
||
64 | ->set('env', $value) |
||
65 | ->set('identity_file', '{{env}}'); |
||
66 | |||
67 | self::assertEquals($value, $host->getIdentityFile()); |
||
68 | } |
||
69 | |||
70 | public function testHostWithUserFromConfig() |
||
71 | { |
||
72 | $parent = new Configuration(); |
||
73 | $parent->set("deploy_user", function () { |
||
74 | return "test_user"; |
||
75 | }); |
||
76 | |||
77 | $host = new Host('host'); |
||
78 | $host->config()->bind($parent); |
||
79 | $host |
||
80 | ->setHostname('host') |
||
81 | ->setRemoteUser('{{deploy_user}}') |
||
82 | ->setPort(22); |
||
83 | |||
84 | self::assertEquals('test_user@host', $host->connectionString()); |
||
85 | } |
||
86 | } |
||
87 |