mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-08 16:29:29 +00:00
Add mongodb module
This commit is contained in:
@@ -57,7 +57,7 @@ jobs:
|
|||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '8.1'
|
php-version: '8.1'
|
||||||
extensions: redis, pgsql
|
extensions: redis, pgsql, mongodb-mongodb/mongo-php-driver@1.15.0
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: composer install --prefer-dist --no-progress
|
run: composer install --prefer-dist --no-progress
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"beluga-php/docker-php": "^1.45"
|
"beluga-php/docker-php": "^1.45"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"ext-mongodb": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"ext-pdo_mysql": "*",
|
"ext-pdo_mysql": "*",
|
||||||
"ext-pdo_pgsql": "*",
|
"ext-pdo_pgsql": "*",
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Testcontainers\Modules;
|
||||||
|
|
||||||
|
use Testcontainers\Container\GenericContainer;
|
||||||
|
use Testcontainers\Wait\WaitForExec;
|
||||||
|
|
||||||
|
class MongoDBContainer extends GenericContainer
|
||||||
|
{
|
||||||
|
private const STARTUP_TIMEOUT_MS = 30_000;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
string $version = 'latest',
|
||||||
|
public readonly string $username = 'test',
|
||||||
|
public readonly string $password = 'test',
|
||||||
|
public readonly string $database = 'test',
|
||||||
|
) {
|
||||||
|
parent::__construct('mongo:' . $version);
|
||||||
|
|
||||||
|
$this
|
||||||
|
->withExposedPorts("27017/tcp")
|
||||||
|
->withEnvironment([
|
||||||
|
"MONGO_INITDB_ROOT_USERNAME" => $this->username,
|
||||||
|
"MONGO_INITDB_ROOT_PASSWORD" => $this->password,
|
||||||
|
"MONGO_INITDB_DATABASE" => $this->database,
|
||||||
|
])
|
||||||
|
->withWait(new WaitForExec([
|
||||||
|
'mongosh', 'admin',
|
||||||
|
'-u', $this->username,
|
||||||
|
'-p', $this->password,
|
||||||
|
'--eval', "'show dbs'",
|
||||||
|
], null, self::STARTUP_TIMEOUT_MS));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Integration;
|
||||||
|
|
||||||
|
use Testcontainers\Container\StartedGenericContainer;
|
||||||
|
use Testcontainers\Modules\MongoDBContainer;
|
||||||
|
use Testcontainers\Tests\Integration\ContainerTestCase;
|
||||||
|
|
||||||
|
class MongoDBContainerTest extends ContainerTestCase
|
||||||
|
{
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->container = (new MongoDBContainer())->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMongoDBContainer(): void
|
||||||
|
{
|
||||||
|
self::assertInstanceOf(StartedGenericContainer::class, $this->container);
|
||||||
|
|
||||||
|
$pingResult = $this->container->exec([
|
||||||
|
'mongosh', 'admin',
|
||||||
|
'-u', 'test',
|
||||||
|
'-p', 'test',
|
||||||
|
'--eval', "'db.runCommand(\"ping\").ok'",
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertEquals(1, $pingResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user