Skip to content

Commit 99f11bb

Browse files
authored
PHPLIB-611: Ensure valid-fail tests are executed by unified test runner (#804)
1 parent ae3dc59 commit 99f11bb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\UnifiedSpecTests;
44

5+
use Exception;
56
use MongoDB\Client;
67
use MongoDB\Collection;
78
use MongoDB\Driver\Exception\ServerException;
@@ -11,7 +12,6 @@
1112
use MongoDB\Tests\FunctionalTestCase;
1213
use stdClass;
1314
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
14-
use Throwable;
1515
use function file_get_contents;
1616
use function gc_collect_cycles;
1717
use function glob;
@@ -87,10 +87,7 @@ private function doTearDown()
8787
parent::tearDown();
8888
}
8989

90-
/**
91-
* @dataProvider providePassingTests
92-
*/
93-
public function testPassingTests(stdClass $test, string $schemaVersion, array $runOnRequirements = null, array $createEntities = null, array $initialData = null)
90+
private function doTestCase(stdClass $test, string $schemaVersion, array $runOnRequirements = null, array $createEntities = null, array $initialData = null)
9491
{
9592
if (! $this->isSchemaVersionSupported($schemaVersion)) {
9693
$this->markTestIncomplete(sprintf('Test format schema version "%s" is not supported', $schemaVersion));
@@ -144,6 +141,14 @@ public function testPassingTests(stdClass $test, string $schemaVersion, array $r
144141
}
145142
}
146143

144+
/**
145+
* @dataProvider providePassingTests
146+
*/
147+
public function testPassingTests(...$args)
148+
{
149+
$this->doTestCase(...$args);
150+
}
151+
147152
public function providePassingTests()
148153
{
149154
return $this->provideTests(__DIR__ . '/valid-pass');
@@ -157,11 +162,13 @@ public function testFailingTests(...$args)
157162
// Cannot use expectException(), as it ignores PHPUnit Exceptions
158163
$failed = false;
159164

165+
// phpcs:disable SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException
160166
try {
161-
$this->testCase(...$args);
162-
} catch (Throwable $e) {
167+
$this->doTestCase(...$args);
168+
} catch (Exception $e) {
163169
$failed = true;
164170
}
171+
// phpcs:enable
165172

166173
assertTrue($failed, 'Expected test to throw an exception');
167174
}

0 commit comments

Comments
 (0)