diff --git a/tests/UnifiedSpecTests/CollectionData.php b/tests/UnifiedSpecTests/CollectionData.php index 3ac6525f9..b7ca2f353 100644 --- a/tests/UnifiedSpecTests/CollectionData.php +++ b/tests/UnifiedSpecTests/CollectionData.php @@ -14,8 +14,10 @@ use function PHPUnit\Framework\assertContainsOnly; use function PHPUnit\Framework\assertIsArray; +use function PHPUnit\Framework\assertIsObject; use function PHPUnit\Framework\assertIsString; use function PHPUnit\Framework\assertNotNull; +use function PHPUnit\Framework\assertObjectNotHasProperty; use function PHPUnit\Framework\assertThat; use function sprintf; @@ -27,6 +29,8 @@ class CollectionData private array $documents; + private array $createOptions = []; + public function __construct(stdClass $o) { assertIsString($o->collectionName); @@ -38,6 +42,15 @@ public function __construct(stdClass $o) assertIsArray($o->documents); assertContainsOnly('object', $o->documents); $this->documents = $o->documents; + + if (isset($o->createOptions)) { + assertIsObject($o->createOptions); + /* The writeConcern option is prohibited here, as prepareInitialData() applies w:majority. Since a session + * option would be ignored by prepareInitialData() we can assert that it is also omitted. */ + assertObjectNotHasProperty('writeConcern', $o->createOptions); + assertObjectNotHasProperty('session', $o->createOptions); + $this->createOptions = (array) $o->createOptions; + } } public function prepareInitialData(Client $client, ?Session $session = null): void @@ -49,13 +62,13 @@ public function prepareInitialData(Client $client, ?Session $session = null): vo $database->dropCollection($this->collectionName, ['session' => $session]); - if (empty($this->documents)) { - $database->createCollection($this->collectionName, ['session' => $session]); - - return; + if (empty($this->documents) || ! empty($this->createOptions)) { + $database->createCollection($this->collectionName, ['session' => $session] + $this->createOptions); } - $database->selectCollection($this->collectionName)->insertMany($this->documents, ['session' => $session]); + if (! empty($this->documents)) { + $database->selectCollection($this->collectionName)->insertMany($this->documents, ['session' => $session]); + } } public function assertOutcome(Client $client): void diff --git a/tests/UnifiedSpecTests/Constraint/Matches.php b/tests/UnifiedSpecTests/Constraint/Matches.php index b793614a4..9a527dcc7 100644 --- a/tests/UnifiedSpecTests/Constraint/Matches.php +++ b/tests/UnifiedSpecTests/Constraint/Matches.php @@ -4,6 +4,7 @@ use LogicException; use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; use MongoDB\BSON\Serializable; use MongoDB\BSON\Type; use MongoDB\Model\BSONArray; @@ -30,10 +31,12 @@ use function PHPUnit\Framework\assertIsBool; use function PHPUnit\Framework\assertIsString; use function PHPUnit\Framework\assertJson; +use function PHPUnit\Framework\assertLessThanOrEqual; use function PHPUnit\Framework\assertMatchesRegularExpression; use function PHPUnit\Framework\assertNotNull; use function PHPUnit\Framework\assertStringStartsWith; use function PHPUnit\Framework\assertThat; +use function PHPUnit\Framework\assertTrue; use function PHPUnit\Framework\containsOnly; use function PHPUnit\Framework\isInstanceOf; use function PHPUnit\Framework\isType; @@ -352,6 +355,14 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $ return; } + if ($name === '$$lte') { + assertTrue(self::isNumeric($operator['$$lte']), '$$lte requires number'); + assertTrue(self::isNumeric($actual), '$actual operand for $$lte should be a number'); + assertLessThanOrEqual($operator['$$lte'], $actual); + + return; + } + throw new LogicException('unsupported operator: ' . $name); } diff --git a/tests/UnifiedSpecTests/Context.php b/tests/UnifiedSpecTests/Context.php index 40ab0c5cc..0faa0611f 100644 --- a/tests/UnifiedSpecTests/Context.php +++ b/tests/UnifiedSpecTests/Context.php @@ -492,6 +492,10 @@ private static function getEnv(string $name): string private static function prepareCollectionOrDatabaseOptions(array $options): array { + if (array_key_exists('timeoutMS', $options)) { + Assert::markTestIncomplete('CSOT is not yet implemented (PHPC-1760)'); + } + Util::assertHasOnlyKeys($options, ['readConcern', 'readPreference', 'writeConcern']); return Util::prepareCommonOptions($options); diff --git a/tests/UnifiedSpecTests/ExpectedError.php b/tests/UnifiedSpecTests/ExpectedError.php index 9d598fa1f..c7ace6d7f 100644 --- a/tests/UnifiedSpecTests/ExpectedError.php +++ b/tests/UnifiedSpecTests/ExpectedError.php @@ -81,6 +81,10 @@ public function __construct(?stdClass $o, EntityMap $entityMap) $this->isClientError = $o->isClientError; } + if (property_exists($o, 'isTimeoutError')) { + Assert::markTestIncomplete('CSOT is not yet implemented (PHPC-1760)'); + } + if (isset($o->errorContains)) { assertIsString($o->errorContains); $this->messageContains = $o->errorContains; diff --git a/tests/UnifiedSpecTests/UnifiedSpecTest.php b/tests/UnifiedSpecTests/UnifiedSpecTest.php index b41a67f38..3552699e9 100644 --- a/tests/UnifiedSpecTests/UnifiedSpecTest.php +++ b/tests/UnifiedSpecTests/UnifiedSpecTest.php @@ -53,9 +53,6 @@ class UnifiedSpecTest extends FunctionalTestCase 'valid-pass/entity-client-cmap-events: events are captured during an operation' => 'PHPC does not implement CMAP', 'valid-pass/expectedEventsForClient-eventType: eventType can be set to command and cmap' => 'PHPC does not implement CMAP', 'valid-pass/expectedEventsForClient-eventType: eventType defaults to command if unset' => 'PHPC does not implement CMAP', - // CSOT is not yet implemented (PHPC-1760) - 'valid-pass/collectionData-createOptions: collection is created with the correct options' => 'CSOT is not yet implemented (PHPC-1760)', - 'valid-pass/operator-lte: special lte matching operator' => 'CSOT is not yet implemented (PHPC-1760)', // libmongoc always adds readConcern to aggregate command 'index-management/search index operations ignore read and write concern: listSearchIndexes ignores read and write concern' => 'libmongoc appends readConcern to aggregate command', // Uses an invalid object name diff --git a/tests/UnifiedSpecTests/UnifiedTestRunner.php b/tests/UnifiedSpecTests/UnifiedTestRunner.php index 92dd0f61a..78e5772a5 100644 --- a/tests/UnifiedSpecTests/UnifiedTestRunner.php +++ b/tests/UnifiedSpecTests/UnifiedTestRunner.php @@ -58,7 +58,7 @@ final class UnifiedTestRunner /** * Support for the following schema versions is incomplete: * - * - 1.9: Only createEntities operation is implemented + * - 1.9: collectionOrDatabaseOptions.timeoutMS and expectedError.isTimeoutError are not implemented * - 1.10: Not implemented * - 1.11: Not implemented, but CMAP is not applicable * - 1.13: Only $$matchAsDocument and $$matchAsRoot is implemented