Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion legacy/src/Service/TunnelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function create(Selection $selection, array $service, ?int $localPort = n
'service' => $service,
];

return new Tunnel($this->getId($metadata), $localPort ?: $this->getPort(), $service['host'], $service['port'], $metadata);
// The 'port' value from the API relationship metadata is a string, but
// Tunnel expects an int, so cast it here.
return new Tunnel($this->getId($metadata), $localPort ?: $this->getPort(), $service['host'], (int) $service['port'], $metadata);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions legacy/tests/Service/TunnelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
namespace Platformsh\Cli\Tests\Service;

use PHPUnit\Framework\TestCase;
use Platformsh\Cli\Selector\Selection;
use Platformsh\Cli\Service\Config;
use Platformsh\Cli\Service\Io;
use Platformsh\Cli\Service\Relationships;
use Platformsh\Cli\Service\TunnelManager;
use Platformsh\Cli\Tunnel\Tunnel;
use Platformsh\Client\Model\Environment;
use Platformsh\Client\Model\Project;

class TunnelManagerTest extends TestCase
{
Expand Down Expand Up @@ -95,6 +98,29 @@ public function testUnserializeOldFormatWithoutId(): void
$this->assertSame(1, $tunnel->metadata['serviceKey']);
}

public function testCreateCastsRemotePortToInt(): void
{
// Relationship data from the API delivers 'port' as a string, but
// Tunnel::$remotePort is typed int. Regression test for #72.
$selection = new Selection(
null,
new Project(['id' => 'proj1']),
new Environment(['id' => 'main']),
'app',
);
$service = [
'host' => 'database.internal',
'port' => '3306',
'_relationship_name' => 'database',
'_relationship_key' => 0,
];

$tunnel = $this->createManager()->create($selection, $service, 30000);

$this->assertSame(3306, $tunnel->remotePort);
$this->assertSame(30000, $tunnel->localPort);
}

public function testUnserializeOldFormatDerivedIdIsStable(): void
{
$json = (string) json_encode([
Expand Down
Loading