Skip to content

Commit 7304097

Browse files
committed
Assert basic structure of test files in data provider
1 parent 369a6f3 commit 7304097

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use stdClass;
1212
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
1313
use Throwable;
14-
use function basename;
1514
use function file_get_contents;
1615
use function glob;
1716
use function MongoDB\BSON\fromJSON;
@@ -119,7 +118,7 @@ public function testPassingTests(stdClass $test, string $schemaVersion, array $r
119118

120119
public function providePassingTests()
121120
{
122-
return $this->provideTests('/home/jmikola/workspace/mongodb/specifications/source/unified-test-format/tests/valid-pass/');
121+
return $this->provideTests('/home/jmikola/workspace/mongodb/specifications/source/unified-test-format/tests/valid-pass');
123122
}
124123

125124
/**
@@ -150,7 +149,7 @@ private function provideTests(string $dir)
150149
{
151150
$testArgs = [];
152151

153-
foreach (glob($dir . '/poc-c*.json') as $filename) {
152+
foreach (glob($dir . '/*.json') as $filename) {
154153
/* Decode the file through the driver's extended JSON parser to
155154
* ensure proper handling of special types. */
156155
$json = toPHP(fromJSON(file_get_contents($filename)));
@@ -160,9 +159,20 @@ private function provideTests(string $dir)
160159
$runOnRequirements = $json->runOnRequirements ?? null;
161160
$createEntities = $json->createEntities ?? null;
162161
$initialData = $json->initialData ?? null;
162+
$tests = $json->tests;
163+
164+
/* Assertions in data providers do not count towards test assertions
165+
* but failures will interrupt the test suite with a warning. */
166+
$message = 'Invalid test file: ' . $filename;
167+
$this->assertInternalType('string', $description, $message);
168+
$this->assertInternalType('string', $schemaVersion, $message);
169+
$this->assertInternalType('array', $tests, $message);
163170

164171
foreach ($json->tests as $test) {
165-
$name = basename($filename) . ': ' . $description . ': ' . $test->description;
172+
$this->assertInternalType('object', $test, $message);
173+
$this->assertInternalType('string', $test->description, $message);
174+
175+
$name = $description . ': ' . $test->description;
166176
$testArgs[$name] = [$test, $schemaVersion, $runOnRequirements, $createEntities, $initialData];
167177
}
168178
}

0 commit comments

Comments
 (0)