some reordering and test optimizations to align new API.

This commit is contained in:
Sergei Shitikov
2024-09-01 14:45:04 +02:00
parent b0e4f60592
commit 5ee4fdc804
6 changed files with 206 additions and 0 deletions
@@ -0,0 +1,45 @@
<?php
namespace Testcontainers\ContainerRuntime;
use Docker\Docker as DockerClient;
class ContainerRuntimeClient
{
/**
* @var DockerClient|null Singleton instance of DockerClient
*/
private static ?DockerClient $dockerClient = null;
/**
* Private constructor to prevent creating instance outside the class.
*/
private function __construct()
{
}
/**
* Returns the singleton DockerClient instance.
*
* @return DockerClient The singleton DockerClient instance.
* @throws \RuntimeException If the DockerClient instance could not be created.
*/
public static function getDockerClient(): DockerClient
{
if (self::$dockerClient === null) {
self::$dockerClient = DockerClient::create();
}
return self::$dockerClient;
}
/**
* Injects a DockerClient instance for testing or special use cases.
*
* @param DockerClient $client The DockerClient instance to set.
*/
public static function setDockerClient(DockerClient $client): void
{
self::$dockerClient = $client;
}
}