Skip to content

PHPLIB-611: Ensure valid-fail tests are executed by unified test runner #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions tests/UnifiedSpecTests/UnifiedSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MongoDB\Tests\UnifiedSpecTests;

use Exception;
use MongoDB\Client;
use MongoDB\Collection;
use MongoDB\Driver\Exception\ServerException;
Expand All @@ -11,7 +12,6 @@
use MongoDB\Tests\FunctionalTestCase;
use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Throwable;
use function file_get_contents;
use function gc_collect_cycles;
use function glob;
Expand Down Expand Up @@ -87,10 +87,7 @@ private function doTearDown()
parent::tearDown();
}

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

/**
* @dataProvider providePassingTests
*/
public function testPassingTests(...$args)
{
$this->doTestCase(...$args);
}

public function providePassingTests()
{
return $this->provideTests(__DIR__ . '/valid-pass');
Expand All @@ -157,11 +162,13 @@ public function testFailingTests(...$args)
// Cannot use expectException(), as it ignores PHPUnit Exceptions
$failed = false;

// phpcs:disable SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException
try {
$this->testCase(...$args);
} catch (Throwable $e) {
$this->doTestCase(...$args);
} catch (Exception $e) {
$failed = true;
}
// phpcs:enable

assertTrue($failed, 'Expected test to throw an exception');
}
Expand Down