Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
31 changes: 28 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1]
php: [8.0, 8.1, 8.2, 8.3, 8.4, 8.5]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v6

- name: Setup PHP
- name: Setup PHP != 8.5
if: ${{ matrix.php != '8.5' }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand All @@ -29,6 +30,30 @@ jobs:
env:
fail-fast: true

- name: Setup PHP 8.5
if: ${{ matrix.php == '8.5' }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, xml, dom, mongodb
tools: pecl
coverage: none
# this ini directive seems to be off by default in PHP 8.5
# see https://github.com/php/php-src/issues/20279
# enable it because codeception relies on it.
ini-values: register_argc_argv=1
env:
fail-fast: true

- name: Install mongodb-database-tools
run: |
sudo apt-get update
sudo apt-get install -y wget gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
sudo apt-get update
sudo apt-get install -y mongodb-database-tools mongodb-mongosh

- name: Validate composer.json and composer.lock
run: composer validate

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": "^8.0",
"codeception/codeception": "^5.0",
"mongodb/mongodb": "^1.12"
"mongodb/mongodb": "^1.12 || ^2.0"
},
"autoload": {
"classmap": [
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Driver/MongoDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function cleanup(): void
public function load(string $dumpFile): void
{
$cmd = sprintf(
'mongo %s %s%s',
'mongosh %s %s%s',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #14 (comment) backwards-compatible solutions were discussed.

@pbromb Do you think that adding a new dump method for mongosh would be possible. It sounds easy to implement at first sight.

This way this PR could be part of a minor release since it wouldn't break BC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@W0rma I've added automatic detection of whether mongosh or the legacy mongo shell is available in the environment.

With this approach, no existing behavior is broken, so the change should be safe to include in a minor release without introducing BC breaks.

$this->host . '/' . $this->dbName,
$this->createUserPasswordCmdString(),
escapeshellarg($dumpFile)
Expand Down
27 changes: 13 additions & 14 deletions tests/unit/Codeception/Module/MongoDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ protected function _setUp()
$this->markTestSkipped('MongoDB is not installed');
}

$cleanupDirty = in_array('cleanup-dirty', $this->getGroups());
$config = $this->mongoConfig + ['cleanup' => $cleanupDirty ? 'dirty' : true];

$client = new \MongoDB\Client();

$this->initMongoModule(true);

$this->db = $client->selectDatabase('test');
$this->userCollection = $this->db->users;

$this->userCollection->insertOne(['id' => 1, 'email' => 'miles@davis.com']);
}

private function initMongoModule($cleanup): void
{
$container = Stub::make(ModuleContainer::class);
$this->module = new MongoDb($container);
$this->module->_setConfig($config);
$this->module->_setConfig($this->mongoConfig + ['cleanup' => $cleanup]);
try {
$this->module->_initialize();
} catch (ModuleException $moduleException) {
$this->markTestSkipped($moduleException->getMessage());
}

$this->db = $client->selectDatabase('test');
$this->userCollection = $this->db->users;

if (!$cleanupDirty) {
$this->userCollection->insertOne(['id' => 1, 'email' => 'miles@davis.com']);
}
}

protected function _tearDown()
Expand Down Expand Up @@ -181,11 +181,10 @@ public function testLoadDump()
}
}

/**
* @group cleanup-dirty
*/
public function testCleanupDirty()
{
$this->initMongoModule('dirty');

$test = $this->createMock(\Codeception\TestInterface::class);
$collection = $this->db->selectCollection('96_bulls');

Expand Down