Thanks to visit codestin.com
Credit goes to github.com

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
5 changes: 4 additions & 1 deletion src/DockerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public function doNotCleanUpAfterExit(): self
return $this;
}

public function mapPort(int $portOnHost, $portOnDocker): self
/**
* @param int|string $portOnHost
*/
public function mapPort($portOnHost, int $portOnDocker): self
{
$this->portMappings[] = new PortMapping($portOnHost, $portOnDocker);

Expand Down
8 changes: 6 additions & 2 deletions src/PortMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

class PortMapping
{
private int $portOnHost;
/** @var int|string */
private $portOnHost;

private int $portOnDocker;

public function __construct(int $portOnHost, int $portOnDocker)
/**
* @param int|string $portOnHost
*/
public function __construct($portOnHost, int $portOnDocker)
{
$this->portOnHost = $portOnHost;

Expand Down
11 changes: 11 additions & 0 deletions tests/DockerContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public function it_can_map_ports()
$this->assertEquals('docker run -p 4848:22 -p 9000:21 -d --rm spatie/docker', $command);
}

/** @test */
public function it_can_map_string_ports()
{
$command = $this->container
->mapPort('127.0.0.1:4848', 22)
->mapPort('0.0.0.0:9000', 21)
->getStartCommand();

$this->assertEquals('docker run -p 127.0.0.1:4848:22 -p 0.0.0.0:9000:21 -d --rm spatie/docker', $command);
}

/** @test */
public function it_can_set_environment_variables()
{
Expand Down