-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caaf59a
commit 0003124
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Platformsh\Client\Tests\Model; | ||
|
||
use Platformsh\Client\Model\Environment; | ||
|
||
class EnvironmentTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetSshUrl() | ||
{ | ||
$multiApp = [ | ||
'pf:ssh:app1' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2' => ['href' => 'ssh://[email protected]'], | ||
]; | ||
$haMultiAppWithInstanceDefault = [ | ||
'pf:ssh:app1' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app1:0' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app1:1' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app1:2' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2:0' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2:1' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2:2' => ['href' => 'ssh://[email protected]'], | ||
]; | ||
$haMultiAppNoInstanceDefault = [ | ||
'pf:ssh:app1:0' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app1:1' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app1:2' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2:0' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2:1' => ['href' => 'ssh://[email protected]'], | ||
'pf:ssh:app2:2' => ['href' => 'ssh://[email protected]'], | ||
]; | ||
|
||
/** @var array{'_links': string[], 'app': string, 'instance': string, 'result': string|false}[] $cases */ | ||
$cases = [ | ||
[ | ||
'_links' => $multiApp, | ||
'app' => 'app1', | ||
'instance' => '', | ||
'result' => '[email protected]', | ||
], | ||
[ | ||
'_links' => $multiApp, | ||
'app' => 'app1', | ||
'instance' => '1', | ||
'result' => false, | ||
], | ||
[ | ||
'_links' => $haMultiAppWithInstanceDefault, | ||
'app' => 'app1', | ||
'instance' => '', | ||
'result' => '[email protected]', | ||
], | ||
[ | ||
'_links' => $haMultiAppWithInstanceDefault, | ||
'app' => 'app1', | ||
'instance' => '0', | ||
'result' => '[email protected]', | ||
], | ||
[ | ||
'_links' => $haMultiAppNoInstanceDefault, | ||
'app' => 'app1', | ||
'instance' => '', | ||
'result' => '[email protected]', | ||
], | ||
[ | ||
'_links' => $haMultiAppNoInstanceDefault, | ||
'app' => 'app1', | ||
'instance' => '1', | ||
'result' => '[email protected]', | ||
], | ||
[ | ||
'_links' => $haMultiAppNoInstanceDefault, | ||
'app' => 'app1', | ||
'instance' => '3', | ||
'result' => false, | ||
], | ||
[ | ||
'_links' => $haMultiAppNoInstanceDefault, | ||
'app' => 'app2', | ||
'instance' => '', | ||
'result' => '[email protected]', | ||
], | ||
]; | ||
foreach ($cases as $i => $case) { | ||
$environment = new Environment(['_links' => $case['_links']]); | ||
if ($case['result'] === false) { | ||
try { | ||
$environment->getSshUrl($case['app'], $case['instance']); | ||
} catch (\InvalidArgumentException $e) { | ||
$this->assertContains('SSH URL not found for instance', $e->getMessage(), "case $i"); | ||
} | ||
continue; | ||
} | ||
$result = $environment->getSshUrl($case['app'], $case['instance']); | ||
$this->assertEquals($case['result'], $result, "case $i"); | ||
} | ||
} | ||
} |