-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-536: Add spec tests for default write concern #726
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace MongoDB\Tests\SpecTests; | ||
|
||
use stdClass; | ||
use function basename; | ||
use function dirname; | ||
use function file_get_contents; | ||
use function glob; | ||
|
||
/** | ||
* @see https://github.com/mongodb/specifications/tree/master/source/read-write-concern | ||
*/ | ||
class ReadWriteConcernSpecTest extends FunctionalTestCase | ||
p-mongo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/** @var array */ | ||
private static $incompleteTests = []; | ||
|
||
/** | ||
* Assert that the expected and actual command documents match. | ||
* | ||
* @param stdClass $expected Expected command document | ||
* @param stdClass $actual Actual command document | ||
*/ | ||
public static function assertCommandMatches(stdClass $expected, stdClass $actual) | ||
{ | ||
foreach ($expected as $key => $value) { | ||
if ($value === null) { | ||
static::assertObjectNotHasAttribute($key, $actual); | ||
unset($expected->{$key}); | ||
} | ||
} | ||
|
||
static::assertDocumentsMatch($expected, $actual); | ||
} | ||
|
||
/** | ||
* Execute an individual test case from the specification. | ||
* | ||
* @dataProvider provideTests | ||
* @param stdClass $test Individual "tests[]" document | ||
* @param array $runOn Top-level "runOn" array with server requirements | ||
* @param array $data Top-level "data" array to initialize collection | ||
* @param string $databaseName Name of database under test | ||
* @param string $collectionName Name of collection under test | ||
*/ | ||
public function testReadWriteConcern(stdClass $test, array $runOn = null, array $data, $databaseName = null, $collectionName = null) | ||
{ | ||
if (isset(self::$incompleteTests[$this->dataDescription()])) { | ||
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]); | ||
} | ||
|
||
if (isset($runOn)) { | ||
$this->checkServerRequirements($runOn); | ||
} | ||
|
||
if (isset($test->skipReason)) { | ||
p-mongo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$this->markTestSkipped($test->skipReason); | ||
} | ||
|
||
$databaseName = $databaseName ?? $this->getDatabaseName(); | ||
$collectionName = $collectionName ?? $this->getCollectionName(); | ||
|
||
$context = Context::fromReadWriteConcern($test, $databaseName, $collectionName); | ||
$this->setContext($context); | ||
|
||
$this->dropTestAndOutcomeCollections(); | ||
$this->insertDataFixtures($data); | ||
|
||
if (isset($test->failPoint)) { | ||
$this->configureFailPoint($test->failPoint); | ||
} | ||
|
||
if (isset($test->expectations)) { | ||
$commandExpectations = CommandExpectations::fromReadWriteConcern($test->expectations); | ||
$commandExpectations->startMonitoring(); | ||
} | ||
|
||
foreach ($test->operations as $operation) { | ||
Operation::fromReadWriteConcern($operation)->assert($this, $context); | ||
} | ||
|
||
if (isset($commandExpectations)) { | ||
$commandExpectations->stopMonitoring(); | ||
$commandExpectations->assert($this, $context); | ||
} | ||
|
||
if (isset($test->outcome->collection->data)) { | ||
$this->assertOutcomeCollectionData($test->outcome->collection->data); | ||
} | ||
} | ||
|
||
public function provideTests() | ||
{ | ||
$testArgs = []; | ||
|
||
foreach (glob(__DIR__ . '/read-write-concern/operation/*.json') as $filename) { | ||
$json = $this->decodeJson(file_get_contents($filename)); | ||
$group = basename(dirname($filename)) . '/' . basename($filename, '.json'); | ||
$runOn = $json->runOn ?? null; | ||
$data = $json->data ?? []; | ||
$databaseName = $json->database_name ?? null; | ||
$collectionName = $json->collection_name ?? null; | ||
|
||
foreach ($json->tests as $test) { | ||
$name = $group . ': ' . $test->description; | ||
$testArgs[$name] = [$test, $runOn, $data, $databaseName, $collectionName]; | ||
} | ||
} | ||
|
||
return $testArgs; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.