added beluga-php/docker-php client and some basic updates to the base Container class

This commit is contained in:
Sergei Shitikov
2024-08-22 16:41:51 +02:00
parent 68a2d6d47c
commit c82e974ab9
8 changed files with 154 additions and 133 deletions
+11 -4
View File
@@ -4,13 +4,11 @@ declare(strict_types=1);
namespace Testcontainers\Wait;
use Docker\Docker;
use Testcontainers\Exception\ContainerNotReadyException;
use Testcontainers\Trait\DockerContainerAwareTrait;
class WaitForHttp implements WaitInterface
{
use DockerContainerAwareTrait;
public const METHOD_GET = 'GET';
public const METHOD_POST = 'POST';
public const METHOD_PUT = 'PUT';
@@ -22,9 +20,11 @@ class WaitForHttp implements WaitInterface
private string $method = 'GET';
private string $path = '/';
private int $statusCode = 200;
private Docker $dockerClient;
public function __construct(private int $port)
{
$this->dockerClient = Docker::create();
}
public static function make(int $port): self
@@ -58,7 +58,14 @@ class WaitForHttp implements WaitInterface
public function wait(string $id): void
{
$containerAddress = self::dockerContainerAddress(containerId: $id);
$containerNetworks = $this->dockerClient->containerInspect($id)->getNetworkSettings()->getNetworks();
$containerAddress = null;
foreach ($containerNetworks as $network) {
if($network->getNetworkID() === $id) {
$containerAddress = $network->getIpAddress();
break;
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d%s', $containerAddress, $this->port, $this->path));