diff --git a/src/ContainerRuntime/ContainerRuntimeClient.php b/src/ContainerRuntime/ContainerRuntimeClient.php new file mode 100644 index 0000000..5728217 --- /dev/null +++ b/src/ContainerRuntime/ContainerRuntimeClient.php @@ -0,0 +1,45 @@ +remove(); + } +} diff --git a/tests/Integration/MariaDBContainerTest.php b/tests/Integration/MariaDBContainerTest.php new file mode 100644 index 0000000..f0629a7 --- /dev/null +++ b/tests/Integration/MariaDBContainerTest.php @@ -0,0 +1,35 @@ +withMariaDBDatabase('foo') + ->withMariaDBUser('bar', 'baz') + ->start(); + } + + public function testMySQLContainer(): void + { + $pdo = new \PDO( + sprintf('mysql:host=%s;port=3306', self::$container->getAddress()), + 'bar', + 'baz', + ); + + $query = $pdo->query('SHOW databases'); + + $this->assertInstanceOf(\PDOStatement::class, $query); + + $databases = $query->fetchAll(\PDO::FETCH_COLUMN); + + $this->assertContains('foo', $databases); + } +} diff --git a/tests/Integration/MySQLContainerTest.php b/tests/Integration/MySQLContainerTest.php new file mode 100644 index 0000000..d625a90 --- /dev/null +++ b/tests/Integration/MySQLContainerTest.php @@ -0,0 +1,35 @@ +withMySQLDatabase('foo') + ->withMySQLUser('bar', 'baz') + ->start(); + } + + public function testMySQLContainer(): void + { + $pdo = new \PDO( + sprintf('mysql:host=%s;port=3306', self::$container->getAddress()), + 'bar', + 'baz', + ); + + $query = $pdo->query('SHOW databases'); + + $this->assertInstanceOf(\PDOStatement::class, $query); + + $databases = $query->fetchAll(\PDO::FETCH_COLUMN); + + $this->assertContains('foo', $databases); + } +} diff --git a/tests/Integration/OpenSearchContainerTest.php b/tests/Integration/OpenSearchContainerTest.php new file mode 100644 index 0000000..92fd1cb --- /dev/null +++ b/tests/Integration/OpenSearchContainerTest.php @@ -0,0 +1,38 @@ +withDisabledSecurityPlugin() + ->start(); + } + + /** + * @throws \JsonException + */ + public function testOpenSearch(): void + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', self::$container->getAddress(), 9200)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $response = (string) curl_exec($ch); + + $this->assertNotEmpty($response); + + /** @var array{cluster_name: string} $data */ + $data = json_decode($response, true, JSON_THROW_ON_ERROR, JSON_THROW_ON_ERROR); + + $this->assertArrayHasKey('cluster_name', $data); + + $this->assertEquals('docker-cluster', $data['cluster_name']); + } +} diff --git a/tests/Integration/PostgreSQLContainerTest.php b/tests/Integration/PostgreSQLContainerTest.php new file mode 100644 index 0000000..7691435 --- /dev/null +++ b/tests/Integration/PostgreSQLContainerTest.php @@ -0,0 +1,35 @@ +withPostgresUser('test') + ->withPostgresDatabase('foo') + ->start(); + } + + public function testPostgreSQLContainer(): void + { + $pdo = new \PDO( + sprintf('pgsql:host=%s;port=5432;dbname=foo', self::$container->getAddress()), + 'test', + 'test', + ); + + $query = $pdo->query('SELECT datname FROM pg_database'); + + $this->assertInstanceOf(\PDOStatement::class, $query); + + $databases = $query->fetchAll(\PDO::FETCH_COLUMN); + + $this->assertContains('foo', $databases); + } +}