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
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"require": {
"ext-curl": "*",
"php": ">= 8.1",
"beluga-php/docker-php": "^1.45",
"beluga-php/docker-php": "^1.45.7",
"beluga-php/docker-php-api": "^7.1.45.5",
"php-http/client-common": "^2.7"
},
"require-dev": {
Expand All @@ -26,9 +27,9 @@
"phpunit/phpunit": "^9.5",
"brianium/paratest": "^6.11",
"friendsofphp/php-cs-fixer": "^3.92",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^2.2",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/extension-installer": "^1.4",
"predis/predis": "^3.0 || ^2.0"
},
"suggest": {
Expand Down
18 changes: 9 additions & 9 deletions src/Container/GenericContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class GenericContainer implements TestContainer

protected ?string $networkName = null;

/** @var array<string> */
/** @var list<string> */
protected array $aliases = [];

protected ?string $user = null;
Expand All @@ -92,7 +92,7 @@ class GenericContainer implements TestContainer
protected const MAX_START_ATTEMPTS = 2;

/**
* @var array<Mount>
* @var list<Mount>
*/
protected array $mounts = [];

Expand Down Expand Up @@ -290,7 +290,7 @@ public function withNetwork(string $networkName): static
*/
public function withAliases(array $aliases): static
{
$this->aliases = $aliases;
$this->aliases = array_values($aliases);

return $this;
}
Expand Down Expand Up @@ -444,15 +444,15 @@ protected function createContainerConfig(): ContainersCreatePostBody

if ($this->networkName !== null) {
$networkingConfig = new NetworkingConfig();
$aliases = $this->aliases ?? [];
$aliases = $this->aliases;
if ($this->name) {
$aliases[] = $this->name;
}
$endpointSettings = new EndpointSettings();
$endpointSettings->setNetworkID($this->networkName);
$endpointSettings->setAliases($aliases);
$endpointsConfig = [
$this->networkName => new EndpointSettings([
'networkID' => $this->networkName,
'aliases' => $aliases,
]),
$this->networkName => $endpointSettings,
];
$networkingConfig->setEndpointsConfig($endpointsConfig);
$containerCreatePostBody->setNetworkingConfig($networkingConfig);
Expand Down Expand Up @@ -497,7 +497,7 @@ protected function createHostConfig(): ?HostConfig
}

/**
* @return array<string, array<int, PortBinding>>
* @return array<string, list<PortBinding>>
*/
protected function createPortBindings(): array
{
Expand Down
11 changes: 7 additions & 4 deletions src/Container/StartedGenericContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function exec(array $command): string

$contents = $this->dockerClient
->execStart($this->lastExecId, $startConfig, Client::FETCH_RESPONSE)
?->getBody()
->getContents() ?? '';
->getBody()
->getContents();

return $this->sanitizeOutput($contents);
}
Expand Down Expand Up @@ -99,8 +99,8 @@ public function logs(): string
['stdout' => true, 'stderr' => true],
DockerRuntimeClient::FETCH_RESPONSE
)
?->getBody()
->getContents() ?? '';
->getBody()
->getContents();

/**
* @var string|false $converted
Expand Down Expand Up @@ -131,6 +131,9 @@ public function getFirstMappedPort(): int
{
$ports = (array) $this->getBoundPorts();
$port = array_key_first($ports);
if ($port === null) {
throw new RuntimeException('Failed to get first mapped port for container');
}
/** @var PortBinding | null $firstPortBinding */
$firstPortBinding = $ports[$port][0] ?? null;
$firstMappedPort = $firstPortBinding?->getHostPort();
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/PortNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function normalizePort(string|int $port, InternetProtocol $interne
}

// Check if the port specification already includes a protocol
if (is_string($port) && !str_contains($port, '/')) {
if (!str_contains($port, '/')) {
return "{$port}/{$internetProtocol->toDockerNotation()}";
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wait/WaitForExec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class WaitForExec extends BaseWaitStrategy
{
/**
* @param array<string> $command
* @param list<string> $command
*/
public function __construct(
protected array $command,
Expand Down
5 changes: 4 additions & 1 deletion src/Wait/WaitForHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function wait(StartedTestContainer $container): void
$this->resolveHostPort($container);
$containerAddress = $container->getHost();

$url = sprintf('%s://%s:%d%s', $this->protocol, $containerAddress, $this->hostPort, $this->path);
$url = "{$this->protocol}://{$containerAddress}:{$this->hostPort}{$this->path}";
$responseCode = $this->makeHttpRequest($url);

if ($responseCode === $this->expectedStatusCode) {
Expand All @@ -120,6 +120,9 @@ public function wait(StartedTestContainer $container): void
}
}

/**
* @param non-empty-string $url
*/
private function makeHttpRequest(string $url): int
{
$ch = curl_init();
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/OpenSearchContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function testOpenSearch(): void

$this->assertNotEmpty($response);

/** @var array{cluster_name: string} $data */
$data = json_decode($response, true, JSON_THROW_ON_ERROR, JSON_THROW_ON_ERROR);
$data = json_decode($response, true, 512, JSON_THROW_ON_ERROR);

$this->assertIsArray($data);
$this->assertArrayHasKey('cluster_name', $data);

$this->assertEquals('docker-cluster', $data['cluster_name']);
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/StartedGenericContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function testShouldStopContainer(): void

$stoppedContainer = $container->stop();

self::assertNotNull($stoppedContainer, 'Stopped container should not be null');
self::assertSame(
$container->getId(),
$stoppedContainer->getId(),
Expand Down
5 changes: 0 additions & 5 deletions tests/Unit/ContainerClient/DockerContainerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private function resetState(): void
{
$reflection = new \ReflectionClass(DockerContainerClient::class);
$property = $reflection->getProperty('dockerClient');
$property->setAccessible(true);
$property->setValue(null, null);

DockerContainerClient::resetFactories();
Expand Down Expand Up @@ -101,7 +100,6 @@ static function (ClientInterface $httpClient) use (&$capturedHttpClient): Docker
private function getPlugins(PluginClient $client): array
{
$prop = (new \ReflectionClass(PluginClient::class))->getProperty('plugins');
$prop->setAccessible(true);

/** @var \Http\Client\Common\Plugin[] $plugins */
$plugins = $prop->getValue($client);
Expand Down Expand Up @@ -131,7 +129,6 @@ private function findHeaderDefaultsPlugin(PluginClient $client): ?HeaderDefaults
private function getHeadersFromPlugin(HeaderDefaultsPlugin $plugin): array
{
$prop = (new \ReflectionClass(HeaderDefaultsPlugin::class))->getProperty('headers');
$prop->setAccessible(true);

/** @var array<string, string> $headers */
$headers = $prop->getValue($plugin);
Expand Down Expand Up @@ -176,7 +173,6 @@ public function testUserAgentVersionDoesNotContainBuildMetadataSuffix(): void
{
$method = (new \ReflectionClass(DockerContainerClient::class))
->getMethod('resolveVersion');
$method->setAccessible(true);

/** @var string $version */
$version = $method->invoke(null);
Expand All @@ -197,7 +193,6 @@ public function testOutOfBoundsExceptionFallsBackToUnknown(): void
// unhandled OutOfBoundsException and the test fails — it is not self-testing.
$method = (new \ReflectionClass(DockerContainerClient::class))
->getMethod('resolveVersion');
$method->setAccessible(true);

/** @var string $result */
$result = $method->invoke(null, 'testcontainers/this-package-does-not-exist');
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Utils/HostResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testReturnsHostFromGatewayWhenRunningInContainer(): void

// Build a fake network inspection response:
$fakeConfig = new class () {
public function getGateway(): ?string
public function getGateway(): string
{
return '172.0.0.1';
}
Expand Down Expand Up @@ -214,7 +214,7 @@ protected function findGateway(string $networkName): ?string
{
return null;
}
protected function findDefaultGateway(): ?string
protected function findDefaultGateway(): string
{
return '172.0.0.2';
}
Expand Down
Loading