Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test on UnifiedTestRunner::setEntityMapObserver() #1129

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions tests/UnifiedSpecTests/UnifiedTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function run(UnifiedTestCase $test): void
*
* This function is primarily used by the Atlas testing workload executor.
*
* @see https://github.com/mongodb-labs/drivers-atlas-testing/
*
* @param callable(EntityMap):void $entityMapObserver
*/
public function setEntityMapObserver(callable $entityMapObserver): void
Copy link
Member

Choose a reason for hiding this comment

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

This is called from the PHP workload executor in the Atlas testing project (see: workload-executor.php).

If you'd like to repurpose this PR you can add a link to the https://github.com/mongodb-labs/drivers-atlas-testing/ repository.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, it was written in the comment above.

I updated the PR to add link and test this feature.

Expand Down
25 changes: 25 additions & 0 deletions tests/UnifiedSpecTests/UnifiedTestRunnerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace MongoDB\Tests\UnifiedSpecTests;

use MongoDB\Tests\FunctionalTestCase;

class UnifiedTestRunnerTest extends FunctionalTestCase
{
public function testEntityMapObserver(): void
{
$test = UnifiedTestCase::fromFile(__DIR__ . '/runner/entity-map-observer.json');
$calls = 0;

$runner = new UnifiedTestRunner(static::getUri());
$runner->setEntityMapObserver(function (EntityMap $entityMap) use (&$calls): void {
$this->assertArrayHasKey('client0', $entityMap);
$this->assertArrayHasKey('database0', $entityMap);
$this->assertArrayHasKey('collection0', $entityMap);
$calls++;
});

$runner->run($test->current());
$this->assertSame(1, $calls);
}
}
68 changes: 68 additions & 0 deletions tests/UnifiedSpecTests/runner/entity-map-observer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"description": "find",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": true,
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "runner-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "coll0"
}
}
],
"initialData": [
{
"collectionName": "coll0",
"databaseName": "runner-tests",
"documents": []
}
],
"tests": [
{
"description": "basic find",
"operations": [
{
"name": "find",
"arguments": {
"filter": {}
},
"object": "collection0",
"expectResult": []
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"find": "coll0",
"filter": {}
},
"commandName": "find",
"databaseName": "runner-tests"
}
}
]
}
]
}
]
}