Skip to content

Commit df783f9

Browse files
committed
CR feedback
1 parent 35cc913 commit df783f9

File tree

5 files changed

+15
-41
lines changed

5 files changed

+15
-41
lines changed

tests/UnifiedSpecTests/CollectionData.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ public function __construct(stdClass $o)
4141
$this->documents = $o->documents;
4242
}
4343

44-
/**
45-
* Prepare collection state for "initialData".
46-
*
47-
* @param Client $client
48-
*/
49-
public function prepare(Client $client)
44+
public function prepareInitialData(Client $client)
5045
{
5146
$database = $client->selectDatabase(
5247
$this->databaseName,
@@ -61,15 +56,9 @@ public function prepare(Client $client)
6156
return;
6257
}
6358

64-
$collection = $database->selectCollection($this->collectionName);
65-
$collection->insertMany($this->documents);
59+
$database->selectCollection($this->collectionName)->insertMany($this->documents);
6660
}
6761

68-
/**
69-
* Assert collection contents for "outcome".
70-
*
71-
* @param Client $client
72-
*/
7362
public function assertOutcome(Client $client)
7463
{
7564
$collection = $client->selectCollection(
@@ -92,8 +81,8 @@ public function assertOutcome(Client $client)
9281
assertNotNull($expectedDocument);
9382
assertNotNull($actualDocument);
9483

95-
/* Disable extra root keys and operators when matching, which is
96-
* effectively an exact match that allows key order variation. */
84+
/* Prohibit extra root keys and disable operators to enforce exact
85+
* matching of documents. Key order variation is still allowed. */
9786
$constraint = new Matches($expectedDocument, null, false, false);
9887
assertThat($actualDocument, $constraint, sprintf('documents[%d] match', $i));
9988
}

tests/UnifiedSpecTests/Constraint/Matches.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
use const PHP_INT_SIZE;
4444

4545
/**
46-
* Constraint that checks if one document matches another.
46+
* Constraint that checks if one value matches another.
4747
*
48-
* The expected value is passed in the constructor.
48+
* The expected value is passed in the constructor. An EntityMap may be supplied
49+
* for resolving operators (e.g. $$matchesEntity). Behavior for allowing extra
50+
* keys in root documents and processing operators is also configurable.
4951
*/
5052
class Matches extends Constraint
5153
{
@@ -242,7 +244,7 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $
242244
'$$type requires string or string[]'
243245
);
244246

245-
$types = is_string($operator['$$type']) ? [$operator['$$type']] : $operator['$$type'];
247+
$types = (array) $operator['$$type'];
246248
$constraints = [];
247249

248250
foreach ($types as $type) {
@@ -286,9 +288,9 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $
286288
}
287289

288290
if ($name === '$$unsetOrMatches') {
289-
/* If the operator is used at the top level, consider null
290-
* values for $actual to be unset. If the operator is nested
291-
* this check is done later document iteration. */
291+
/* If the operator is used at the top level, consider null values
292+
* for $actual to be unset. If the operator is nested, this check is
293+
* done later during document iteration. */
292294
if ($keyPath === '' && $actual === null) {
293295
return;
294296
}

tests/UnifiedSpecTests/Context.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use function array_fill_keys;
1616
use function array_key_exists;
1717
use function array_keys;
18-
use function assertArrayHasKey;
19-
use function assertArrayNotHasKey;
2018
use function assertContains;
2119
use function assertCount;
2220
use function assertEmpty;
@@ -83,7 +81,6 @@ public function createEntities(array $entities)
8381

8482
$id = $def->id ?? null;
8583
assertInternalType('string', $id);
86-
assertArrayNotHasKey($id, $this->entityMap);
8784

8885
switch ($type) {
8986
case 'client':
@@ -128,7 +125,6 @@ public function prepareOperationArguments(array $args) : array
128125

129126
if (array_key_exists('session', $args)) {
130127
assertInternalType('string', $args['session']);
131-
assertArrayHasKey($args['session'], $this->entityMap);
132128
$session = $this->entityMap[$args['session']];
133129
assertInstanceOf(Session::class, $session);
134130
$args['session'] = $session;
@@ -212,7 +208,6 @@ private function createCollection(stdClass $o) : Collection
212208

213209
assertInternalType('string', $collectionName);
214210
assertInternalType('string', $database);
215-
assertArrayHasKey($database, $this->entityMap);
216211

217212
$database = $this->entityMap[$database];
218213
assertInstanceOf(Database::class, $database);
@@ -236,7 +231,6 @@ private function createDatabase(stdClass $o) : Database
236231

237232
assertInternalType('string', $databaseName);
238233
assertInternalType('string', $client);
239-
assertArrayHasKey($client, $this->entityMap);
240234

241235
$client = $this->entityMap[$client];
242236
assertInstanceOf(Client::class, $client);

tests/UnifiedSpecTests/RunOnRequirement.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ public function __construct(stdClass $o)
4848
}
4949
}
5050

51-
/**
52-
* Checks if the requirements are satisfied.
53-
*
54-
* @param string $serverVersion
55-
* @param string $topology
56-
* @return boolean
57-
*/
58-
public function isSatisfied(string $serverVersion, string $topology)
51+
public function isSatisfied(string $serverVersion, string $topology) : bool
5952
{
6053
if (isset($this->minServerVersion) && version_compare($serverVersion, $this->minServerVersion, '<')) {
6154
return false;

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ private function getCachedTopology()
225225
*/
226226
private function isSchemaVersionSupported($schemaVersion)
227227
{
228-
if (version_compare($schemaVersion, '1.0', '>=') && version_compare($schemaVersion, '1.1', '<')) {
229-
return true;
230-
}
231-
232-
return false;
228+
return version_compare($schemaVersion, '1.0', '>=') && version_compare($schemaVersion, '1.1', '<');
233229
}
234230

235231
/**
@@ -277,7 +273,7 @@ private function prepareInitialData(array $initialData)
277273

278274
foreach ($initialData as $data) {
279275
$collectionData = new CollectionData($data);
280-
$collectionData->prepare(self::$internalClient);
276+
$collectionData->prepareInitialData(self::$internalClient);
281277
}
282278
}
283279
}

0 commit comments

Comments
 (0)