mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 05:29:36 +00:00
added beluga-php/docker-php client and some basic updates to the base Container class
This commit is contained in:
@@ -4,17 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace Testcontainers\Wait;
|
||||
|
||||
use Docker\Docker;
|
||||
use JsonException;
|
||||
use RuntimeException;
|
||||
use Testcontainers\Exception\ContainerNotReadyException;
|
||||
use Testcontainers\Trait\DockerContainerAwareTrait;
|
||||
|
||||
final class WaitForTcpPortOpen implements WaitInterface
|
||||
{
|
||||
use DockerContainerAwareTrait;
|
||||
private Docker $dockerClient;
|
||||
|
||||
public function __construct(private readonly int $port, private readonly ?string $network = null)
|
||||
{
|
||||
$this->dockerClient = Docker::create();
|
||||
}
|
||||
|
||||
public static function make(int $port, ?string $network = null): self
|
||||
@@ -27,7 +28,16 @@ final class WaitForTcpPortOpen implements WaitInterface
|
||||
*/
|
||||
public function wait(string $id): void
|
||||
{
|
||||
if (@fsockopen(self::dockerContainerAddress(containerId: $id, networkName: $this->network), $this->port) === false) {
|
||||
$containerInspectResult = $this->dockerClient->containerInspect($id);
|
||||
$dockerContainerNetworks = $containerInspectResult->getNetworkSettings()->getNetworks();
|
||||
$dockerContainerAddress = '';
|
||||
foreach ($dockerContainerNetworks as $network) {
|
||||
if ($network->getNetworkID() === $this->network) {
|
||||
$dockerContainerAddress = $network->getIPAddress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (@fsockopen($dockerContainerAddress, $this->port) === false) {
|
||||
throw new ContainerNotReadyException($id, new RuntimeException('Unable to connect to container TCP port'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user