mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 05:29:36 +00:00
Code reuse on working with docker networks
This commit is contained in:
@@ -58,7 +58,7 @@ class WaitForHttp implements WaitInterface
|
||||
|
||||
public function wait(string $id): void
|
||||
{
|
||||
$containerAddress = $this->getContainerAddress(containerId: $id);
|
||||
$containerAddress = self::dockerContainerAddress(containerId: $id);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d%s', $containerAddress, $this->port, $this->path));
|
||||
|
||||
@@ -13,13 +13,13 @@ final class WaitForTcpPortOpen implements WaitInterface
|
||||
{
|
||||
use DockerContainerAwareTrait;
|
||||
|
||||
public function __construct(private readonly int $port)
|
||||
public function __construct(private readonly int $port, private readonly ?string $network = null)
|
||||
{
|
||||
}
|
||||
|
||||
public static function make(int $port): self
|
||||
public static function make(int $port, ?string $network = null): self
|
||||
{
|
||||
return new self($port);
|
||||
return new self($port, $network);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ final class WaitForTcpPortOpen implements WaitInterface
|
||||
*/
|
||||
public function wait(string $id): void
|
||||
{
|
||||
if (@fsockopen($this->getContainerAddress($id), $this->port) === false) {
|
||||
if (@fsockopen(self::dockerContainerAddress(containerId: $id, networkName: $this->network), $this->port) === false) {
|
||||
throw new ContainerNotReadyException($id, new RuntimeException('Unable to connect to container TCP port'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user