Skip to content

Commit acec00c

Browse files
committed
Replace skip by whitelist/blacklist in draft test cases
1 parent 77b7e38 commit acec00c

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

tests/JsonSchema/Tests/Drafts/BaseDraftTestCase.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,27 @@ abstract class BaseDraftTestCase extends BaseTestCase
1111
private function setUpTests($isValid)
1212
{
1313
$filePaths = $this->getFilePaths();
14-
$skippedTests = $this->getSkippedTests();
14+
$whiteList = $this->getWhiteList();
15+
$blackList = $this->getBlackList();
1516
$tests = array();
1617

1718
foreach ($filePaths as $path) {
1819
foreach (glob($path . '/*.json') as $file) {
19-
if (!in_array(basename($file), $skippedTests)) {
20+
$name = basename($file);
21+
$whiteListed = $whiteList && in_array($name, $whiteList);
22+
$blackListed = !$whiteList && $blackList && in_array($name, $blackList);
23+
$mustSkip = $whiteList && !$whiteListed || $blackListed;
24+
25+
if (!$mustSkip) {
2026
$suites = json_decode(file_get_contents($file));
27+
2128
foreach ($suites as $suite) {
2229
foreach ($suite->tests as $test) {
2330
if ($isValid === $test->valid) {
24-
$tests[] = array(json_encode($test->data), json_encode($suite->schema));
31+
$tests[] = array(
32+
json_encode($test->data),
33+
json_encode($suite->schema)
34+
);
2535
}
2636
}
2737
}
@@ -44,5 +54,26 @@ public function getValidTests()
4454

4555
protected abstract function getFilePaths();
4656

47-
protected abstract function getSkippedTests();
57+
/**
58+
* Returns the list of tests to run, or false, if all
59+
* the tests must be included in the suite by default.
60+
*
61+
* @return false|string[]
62+
*/
63+
protected function getWhiteList()
64+
{
65+
return false;
66+
}
67+
68+
/**
69+
* Returns the list of tests not to run, or false, if no test
70+
* should be excluded from the suite by default. Note that
71+
* this list is ignored if a white list has been provided.
72+
*
73+
* @return false|string[]
74+
*/
75+
protected function getBlackList()
76+
{
77+
return false;
78+
}
4879
}

tests/JsonSchema/Tests/Drafts/Draft3Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected function getFilePaths()
1212
);
1313
}
1414

15-
protected function getSkippedTests()
15+
protected function getBlackList()
1616
{
1717
return array(
1818
'ref.json',

tests/JsonSchema/Tests/Drafts/Draft4Test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected function getFilePaths()
1212
);
1313
}
1414

15-
protected function getSkippedTests()
15+
protected function getBlackList()
1616
{
1717
return array(
1818
// Not Yet Implemented
@@ -25,5 +25,4 @@ protected function getSkippedTests()
2525
'zeroTerminatedFloats.json'
2626
);
2727
}
28-
2928
}

0 commit comments

Comments
 (0)