diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4273c5a..1659e7d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -57,7 +57,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.1' - extensions: redis, pgsql + extensions: redis, pgsql, mongodb-mongodb/mongo-php-driver@1.15.0 - name: Install dependencies run: composer install --prefer-dist --no-progress diff --git a/composer.json b/composer.json index 4632765..01d13a1 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "beluga-php/docker-php": "^1.45" }, "require-dev": { + "ext-mongodb": "*", "ext-pdo": "*", "ext-pdo_mysql": "*", "ext-pdo_pgsql": "*", diff --git a/src/Modules/MongoDBContainer.php b/src/Modules/MongoDBContainer.php new file mode 100644 index 0000000..739d31a --- /dev/null +++ b/src/Modules/MongoDBContainer.php @@ -0,0 +1,36 @@ +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)); + } +} diff --git a/tests/Integration/MongoDBContainerTest.php b/tests/Integration/MongoDBContainerTest.php new file mode 100644 index 0000000..e388a04 --- /dev/null +++ b/tests/Integration/MongoDBContainerTest.php @@ -0,0 +1,31 @@ +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); + } +}