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
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2643624-4.interdiff.txt | 587 bytes | neclimdul |
| #4 | fix-2643624-4.patch | 2.28 KB | neclimdul |
Comments
Comment #2
mile23This 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.
Comment #3
neclimdulWe can let phpunit, setUp, and tearDown do the work of isolating the tests.
Comment #4
neclimdulSelf 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.
Comment #5
mile23It'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.
Comment #9
mile23This is fixed by #2810083: Duplicate test results per fail/exception