function SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand

Test the round trip for PHPUnit execution status codes.

Also tests backwards-compatibility of PhpUnitTestRunner::runTests().

@covers ::simpletest_run_phpunit_tests

@dataProvider provideStatusCodes

@expectedDeprecation simpletest_run_phpunit_tests is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::runTests() instead. See https://www.drupal.org/node/2948547 @expectedDeprecation simpletest_phpunit_xml_filepath is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547

File

core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php, line 112

Class

SimpletestPhpunitRunCommandTest
Tests <a href="/api/drupal/core%21modules%21simpletest%21simpletest.module/function/simpletest_run_phpunit_tests/8.9.x" title="Executes PHPUnit tests and returns the results of the run." class="local">simpletest_run_phpunit_tests</a>() handles PHPunit fatals correctly.

Namespace

Drupal\Tests\simpletest\Unit

Code

public function testSimpletestPhpUnitRunCommand($status, $label) {
    // Add a default database connection in order for
    // Database::getConnectionInfoAsUrl() to return valid information.
    Database::addConnectionInfo('default', 'default', [
        'driver' => 'mysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'port' => 3306,
        'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
    ]);
    $test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
    putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
    // Test against simpletest_run_phpunit_tests().
    $bc_ret = simpletest_run_phpunit_tests($test_id, [
        SimpletestPhpunitRunCommandTestWillDie::class,
    ]);
    $this->assertSame($bc_ret[0]['status'], $label);
    // Test against PhpUnitTestRunner::runTests().
    $runner = PhpUnitTestRunner::create($this->fixtureContainer);
    $ret = $runner->runTests($test_id, [
        SimpletestPhpunitRunCommandTestWillDie::class,
    ]);
    $this->assertSame($ret[0]['status'], $label);
    // Unset our environmental variable.
    putenv('SimpletestPhpunitRunCommandTestWillDie');
    unlink(simpletest_phpunit_xml_filepath($test_id));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.