Problem/Motivation

In #2641632-4: Refactor simpletest's *_phpunit_*() (and junit) functions etc. to a class, deprecate I discovered a bug in SimpletestPhpunitRunCommandTest.

SimpletestPhpunitRunCommandTest, which I have to say is a super-awesome great test to have, is full of bugs.

It looks like this:

function testSimpletestPhpUnitRunCommand() {
  include_once __DIR__ . '/../../fixtures/simpletest_phpunit_run_command_test.php';
  $app_root = __DIR__ . '/../../../../../..';
  include_once "$app_root/core/modules/simpletest/simpletest.module";
  $container = new ContainerBuilder;
  $container->set('app.root', $app_root);
  $file_system = $this->prophesize('Drupal\Core\File\FileSystemInterface');
  $file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir());
  $container->set('file_system', $file_system->reveal());
  \Drupal::setContainer($container);
  $test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
  foreach (['pass', 'fail'] as $status) {
    putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
    $ret = simpletest_run_phpunit_tests($test_id, ['Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTestWillDie']);
    $this->assertSame($ret[0]['status'], $status);
  }
  unlink(simpletest_phpunit_xml_filepath($test_id));
}

It sets the file_system service to deal with the temp file directory, which is good.

Then it generates a temp file and uses its name as the test id, which is bad, because the test id is supposed to be an integer, and now we have an unneeded file in tmp.

It also uses the same id for two test runs, which means the files will overwrite themselves and thus we lose the benefit of expecting that two files will be generated.

Proposed resolution

Remove the need for an extraneous temp file which is never deleted.

Change the test ID to be an integer.

Remove the two test results files as part of the test.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Mile23 created an issue. See original summary.

mile23’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.27 KB

This is the same as the test-only patch in #2641632-4: Refactor simpletest's *_phpunit_*() (and junit) functions etc. to a class, deprecate.

It sets the test ID to an integer and then increments the ID for subsequent tests.

Then it can decrement the ID for result file expectations.

neclimdul’s picture

StatusFileSize
new2.28 KB

We can let phpunit, setUp, and tearDown do the work of isolating the tests.

neclimdul’s picture

StatusFileSize
new2.28 KB
new587 bytes
+++ b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php
@@ -30,13 +42,33 @@ function testSimpletestPhpUnitRunCommand() {
+    parent::tearDown();
+    unlink(simpletest_phpunit_xml_filepath($this->tempName));

Self review. I made a note not to do this when writing the patch but somehow did it anyways... This _should_ work but technically its the wrong order.

mile23’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php
@@ -30,13 +42,33 @@ function testSimpletestPhpUnitRunCommand() {
+    $this->tempName = basename(tempnam(sys_get_temp_dir(), 'xxx'));

It's kind of the point of the change here that we don't need to create this temp file. Also that we use an int for the test ID, rather than relying on type conversion from the temp file's name.

Also you've removed the part where we expect to have an XML result file each for a pass or a fail. There should be an error if it isn't there to unlink. That's why I didn't use tearDown().. It's part of the test.

Unwrapping to a data provider is good.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Status: Needs work » Closed (duplicate)