Skip to content

Commit 0003124

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

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

tests/Model/EnvironmentTest.php

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

0 commit comments

Comments
 (0)