Commit d24a8906 authored by alexpott's avatar alexpott

Issue #2566963 by chx: Follow up of 2560643 Add test coverage

parent da501fe7
......@@ -229,7 +229,7 @@ function simpletest_process_phpunit_results($phpunit_results) {
* Path to the PHPUnit XML file to use for the current $test_id.
*/
function simpletest_phpunit_xml_filepath($test_id) {
return drupal_realpath('public://simpletest') . '/phpunit-' . $test_id . '.xml';
return \Drupal::service('file_system')->realpath('public://simpletest') . '/phpunit-' . $test_id . '.xml';
}
/**
......
<?php
namespace Drupal\Tests\simpletest\Unit;
use Drupal\Tests\UnitTestCase;
/**
* This test crashes PHP.
*
* To avoid accidentally running, it is not in a normal PSR-4 directory, the
* file name does not adhere to PSR-4 and an environment variable also needs to
* be set for the crash to happen.
*/
class SimpletestPhpunitRunCommandTestWillDie extends UnitTestCase {
public function testWillDie() {
if (getenv('SimpletestPhpunitRunCommandTestWillDie') === 'fail') {
exit(1);
}
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest.
*/
namespace Drupal\Tests\simpletest\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
* Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
*
* @group simpletest
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class SimpletestPhpunitRunCommandTest extends UnitTestCase {
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));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment