Skip to content

Commit

Permalink
Add some getSshUrl() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Oct 26, 2022
1 parent caaf59a commit 0003124
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions tests/Model/EnvironmentTest.php
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");
}
}
}

0 comments on commit 0003124

Please sign in to comment.