You are here

public function SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand in Drupal 8

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 simpletest_run_phpunit_tests() 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));
}