Skip to content

Commit 05200ba

Browse files
committed
Add some getSshUrl() tests
1 parent caaf59a commit 05200ba

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

tests/Model/EnvironmentTest.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
namespace Platformsh\Client\Tests\Model;
4+
5+
use Platformsh\Client\Model\Environment;
6+
7+
class EnvironmentTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testGetSshUrl()
10+
{
11+
$multiApp = [
12+
'ssh' => ['href' => 'ssh://[email protected]'],
13+
'pf:ssh:app1' => ['href' => 'ssh://[email protected]'],
14+
'pf:ssh:app2' => ['href' => 'ssh://[email protected]'],
15+
];
16+
$haMultiAppWithInstanceDefault = [
17+
'ssh' => ['href' => 'ssh://[email protected]'],
18+
'pf:ssh:app1' => ['href' => 'ssh://[email protected]'],
19+
'pf:ssh:app1:0' => ['href' => 'ssh://[email protected]'],
20+
'pf:ssh:app1:1' => ['href' => 'ssh://[email protected]'],
21+
'pf:ssh:app1:2' => ['href' => 'ssh://[email protected]'],
22+
'pf:ssh:app2' => ['href' => 'ssh://[email protected]'],
23+
'pf:ssh:app2:0' => ['href' => 'ssh://[email protected]'],
24+
'pf:ssh:app2:1' => ['href' => 'ssh://[email protected]'],
25+
'pf:ssh:app2:2' => ['href' => 'ssh://[email protected]'],
26+
];
27+
$haMultiAppNoInstanceDefault = [
28+
'ssh' => ['href' => 'ssh://[email protected]'],
29+
'pf:ssh:app1:0' => ['href' => 'ssh://[email protected]'],
30+
'pf:ssh:app1:1' => ['href' => 'ssh://[email protected]'],
31+
'pf:ssh:app1:2' => ['href' => 'ssh://[email protected]'],
32+
'pf:ssh:app2:0' => ['href' => 'ssh://[email protected]'],
33+
'pf:ssh:app2:1' => ['href' => 'ssh://[email protected]'],
34+
'pf:ssh:app2:2' => ['href' => 'ssh://[email protected]'],
35+
];
36+
37+
/** @var array{'_links': string[], 'app': string, 'instance': string, 'result': string|false}[] $cases */
38+
$cases = [
39+
[
40+
'_links' => $multiApp,
41+
'app' => 'app1',
42+
'instance' => '',
43+
'result' => '[email protected]',
44+
],
45+
[
46+
'_links' => $multiApp,
47+
'app' => 'app1',
48+
'instance' => '1',
49+
'result' => false,
50+
],
51+
[
52+
'_links' => $haMultiAppWithInstanceDefault,
53+
'app' => 'app1',
54+
'instance' => '',
55+
'result' => '[email protected]',
56+
],
57+
[
58+
'_links' => $haMultiAppWithInstanceDefault,
59+
'app' => 'app1',
60+
'instance' => '0',
61+
'result' => '[email protected]',
62+
],
63+
[
64+
'_links' => $haMultiAppNoInstanceDefault,
65+
'app' => 'app1',
66+
'instance' => '',
67+
'result' => '[email protected]',
68+
],
69+
[
70+
'_links' => $haMultiAppNoInstanceDefault,
71+
'app' => 'app1',
72+
'instance' => '1',
73+
'result' => '[email protected]',
74+
],
75+
[
76+
'_links' => $haMultiAppNoInstanceDefault,
77+
'app' => 'app1',
78+
'instance' => '3',
79+
'result' => false,
80+
],
81+
[
82+
'_links' => $haMultiAppNoInstanceDefault,
83+
'app' => 'app2',
84+
'instance' => '',
85+
'result' => '[email protected]',
86+
],
87+
];
88+
foreach ($cases as $i => $case) {
89+
$environment = new Environment(['id' => 'main', 'status' => 'active', '_links' => $case['_links']], 'https://example.com/projects/foo');
90+
if ($case['result'] === false) {
91+
try {
92+
$environment->getSshUrl($case['app'], $case['instance']);
93+
} catch (\InvalidArgumentException $e) {
94+
$this->assertContains('SSH URL not found for instance', $e->getMessage(), "case $i");
95+
}
96+
continue;
97+
}
98+
$result = $environment->getSshUrl($case['app'], $case['instance']);
99+
$this->assertEquals($case['result'], $result, "case $i");
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)