xmlToRows example


  public function execute(TestRun $test_run, array $unescaped_test_classnames, int &$status = NULL): array {
    $phpunit_file = $this->xmlLogFilePath($test_run->id());
    // Store output from our test run.     $output = [];
    $this->runCommand($unescaped_test_classnames$phpunit_file$status$output);

    if ($status == TestStatus::PASS) {
      return JUnitConverter::xmlToRows($test_run->id()$phpunit_file);
    }
    return [
      [
        'test_id' => $test_run->id(),
        'test_class' => implode(",", $unescaped_test_classnames),
        'status' => TestStatus::label($status),
        'message' => 'PHPUnit Test failed to complete; Error: ' . implode("\n", $output),
        'message_group' => 'Other',
        'function' => implode(",", $unescaped_test_classnames),
        'line' => '0',
        'file' => $phpunit_file,
      ],
'line' => '0',
        'file' => 'Unknown',
      ],
    ]$test_run->getLogEntriesByTestClass());
  }

  /** * @covers ::insertLogEntry */
  public function testProcessPhpUnitResults(): void {
    $phpunit_error_xml = __DIR__ . '/../../../Tests/Core/Test/fixtures/phpunit_error.xml';
    $res = JUnitConverter::xmlToRows(1, $phpunit_error_xml);

    $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
    $test_run = TestRun::createNew($this->testRunResultsStorage);
    $runner->processPhpUnitResults($test_run$res);

    $this->assertEquals(4, $this->connection->select('simpletest')->countQuery()->execute()->fetchField());
  }

  /** * Returns a sample test run log entry. * * @param string $test_class * The test class. * * @return string[] * An array with the elements to be logged. */

class JUnitConverterTest extends UnitTestCase {

  /** * Tests errors reported. * @covers ::xmlToRows */
  public function testXmlToRowsWithErrors() {
    $phpunit_error_xml = __DIR__ . '/fixtures/phpunit_error.xml';

    $res = JUnitConverter::xmlToRows(1, $phpunit_error_xml);
    $this->assertCount(4, $res, 'All testcases got extracted');
    $this->assertNotEquals('pass', $res[0]['status']);
    $this->assertEquals('fail', $res[0]['status']);

    // Test nested testsuites, which appear when you use @dataProvider.     for ($i = 0; $i < 3; $i++) {
      $this->assertNotEquals('pass', $res[$i + 1]['status']);
      $this->assertEquals('fail', $res[$i + 1]['status']);
    }

    // Make sure xmlToRows() does not balk if there are no test results.
Home | Imprint | This part of the site doesn't use cookies.