Skip to content

Use named datasets in spec tests #650

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
Jul 30, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions tests/Collection/CrudSpecFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function setUp()
*/
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion)
{
$this->setName(str_replace(' ', '_', $test['description']));

if (isset($minServerVersion) || isset($maxServerVersion)) {
$this->checkServerVersion($minServerVersion, $maxServerVersion);
}
Expand Down Expand Up @@ -71,7 +69,8 @@ public function provideSpecificationTests()
$maxServerVersion = isset($json['maxServerVersion']) ? $json['maxServerVersion'] : null;

foreach ($json['tests'] as $test) {
$testArgs[] = [$json['data'], $test, $minServerVersion, $maxServerVersion];
$name = str_replace(' ', '_', $test['description']);
$testArgs[$name] = [$json['data'], $test, $minServerVersion, $maxServerVersion];
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/GridFS/SpecFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function setUp()
*/
public function testSpecification(array $initialData, array $test)
{
$this->setName(str_replace(' ', '_', $test['description']));
$this->initializeData($initialData);

if (isset($test['arrange'])) {
Expand Down Expand Up @@ -77,7 +76,8 @@ public function provideSpecificationTests()
$json = json_decode(file_get_contents($filename), true);

foreach ($json['tests'] as $test) {
$testArgs[] = [$json['data'], $test];
$name = str_replace(' ', '_', $test['description']);
$testArgs[$name] = [$json['data'], $test];
}
}

Expand Down
17 changes: 7 additions & 10 deletions tests/SpecTests/ChangeStreamsSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ public static function assertResult(array $expectedDocuments, array $actualDocum
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param string $name Test name
* @param stdClass $test Individual "tests[]" document
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
* @param string $database2Name Name of alternate database under test
* @param string $collection2Name Name of alternate collection under test
* @param stdClass $test Individual "tests[]" document
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
* @param string $database2Name Name of alternate database under test
* @param string $collection2Name Name of alternate collection under test
*/
public function testChangeStreams($name, stdClass $test, $databaseName = null, $collectionName = null, $database2Name = null, $collection2Name = null)
public function testChangeStreams(stdClass $test, $databaseName = null, $collectionName = null, $database2Name = null, $collection2Name = null)
{
$this->setName($name);

$this->checkServerRequirements($this->createRunOn($test));

if (!isset($databaseName, $collectionName, $database2Name, $collection2Name)) {
Expand Down Expand Up @@ -151,7 +148,7 @@ public function provideTests()

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[] = [$name, $test, $databaseName, $collectionName, $database2Name, $collection2Name];
$testArgs[$name] = [$test, $databaseName, $collectionName, $database2Name, $collection2Name];
}
}

Expand Down
7 changes: 2 additions & 5 deletions tests/SpecTests/CommandMonitoringSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,13 @@ public static function assertCommandReplyMatches(stdClass $expected, stdClass $a
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param string $name Test name
* @param stdClass $test Individual "tests[]" document
* @param array $data Top-level "data" array to initialize collection
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testCommandMonitoring($name, stdClass $test, array $data, $databaseName = null, $collectionName = null)
public function testCommandMonitoring(stdClass $test, array $data, $databaseName = null, $collectionName = null)
{
$this->setName($name);

$this->checkServerRequirements($this->createRunOn($test));

$databaseName = isset($databaseName) ? $databaseName : $this->getDatabaseName();
Expand Down Expand Up @@ -177,7 +174,7 @@ public function provideTests()

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[] = [$name, $test, $data, $databaseName, $collectionName];
$testArgs[$name] = [$test, $data, $databaseName, $collectionName];
}
}

Expand Down
9 changes: 4 additions & 5 deletions tests/SpecTests/CrudSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param string $name Test name
* @param stdClass $test Individual "tests[]" document
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testCrud($name, stdClass $test, array $runOn = null, array $data, $databaseName = null, $collectionName = null)
public function testCrud(stdClass $test, array $runOn = null, array $data, $databaseName = null, $collectionName = null)
{
if (isset(self::$incompleteTests[$name])) {
$this->markTestIncomplete(self::$incompleteTests[$name]);
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
}

if (isset($runOn)) {
Expand Down Expand Up @@ -104,7 +103,7 @@ public function provideTests()

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[$name] = [$name, $test, $runOn, $data, $databaseName, $collectionName];
$testArgs[$name] = [$test, $runOn, $data, $databaseName, $collectionName];
}
}

Expand Down
7 changes: 2 additions & 5 deletions tests/SpecTests/RetryableWritesSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ class RetryableWritesSpecTest extends FunctionalTestCase
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param string $name Test name
* @param stdClass $test Individual "tests[]" document
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
*/
public function testRetryableWrites($name, stdClass $test, array $runOn = null, array $data)
public function testRetryableWrites(stdClass $test, array $runOn = null, array $data)
{
$this->setName($name);

// TODO: Revise this once a test environment with multiple mongos nodes is available (see: PHPLIB-430)
if (isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isShardedCluster()) {
$this->markTestSkipped('"useMultipleMongoses" is not supported');
Expand Down Expand Up @@ -63,7 +60,7 @@ public function provideTests()

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[] = [$name, $test, $runOn, $data];
$testArgs[$name] = [$test, $runOn, $data];
}
}

Expand Down
21 changes: 9 additions & 12 deletions tests/SpecTests/TransactionsSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,16 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param string $name Test name
* @param stdClass $test Individual "tests[]" document
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
* @param stdClass $test Individual "tests[]" document
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testTransactions($name, stdClass $test, array $runOn = null, array $data, $databaseName = null, $collectionName = null)
public function testTransactions(stdClass $test, array $runOn = null, array $data, $databaseName = null, $collectionName = null)
{
$this->setName($name);

if (isset(self::$incompleteTests[$name])) {
$this->markTestIncomplete(self::$incompleteTests[$name]);
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
}

// TODO: Revise this once a test environment with multiple mongos nodes is available (see: PHPLIB-430)
Expand Down Expand Up @@ -192,7 +189,7 @@ public function provideTests()

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[] = [$name, $test, $runOn, $data, $databaseName, $collectionName];
$testArgs[$name] = [$test, $runOn, $data, $databaseName, $collectionName];
}
}

Expand Down