class JUnitConverterTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php \Drupal\Tests\Core\Test\JUnitConverterTest
- 8.9.x core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php \Drupal\Tests\Core\Test\JUnitConverterTest
- 11.x core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php \Drupal\Tests\Core\Test\JUnitConverterTest
Tests Drupal\Core\Test\JUnitConverter.
This test class has significant overlap with Drupal\Tests\simpletest\Kernel\PhpUnitErrorTest.
@coversDefaultClass \Drupal\Core\Test\JUnitConverter
@group Test @group simpletest
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Test\JUnitConverterTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of JUnitConverterTest
See also
\Drupal\Tests\simpletest\Kernel\PhpUnitErrorTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Test/ JUnitConverterTest.php, line 24
Namespace
Drupal\Tests\Core\TestView source
class JUnitConverterTest extends UnitTestCase {
/**
* Tests errors reported.
* @covers ::xmlToRows
*/
public function testXmlToRowsWithErrors() : void {
$phpunit_error_xml = __DIR__ . '/fixtures/phpunit_error.xml';
$res = JUnitConverter::xmlToRows(1, $phpunit_error_xml);
$this->assertCount(4, $res, 'All test cases 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.
$this->assertSame([], JUnitConverter::xmlToRows(1, 'does_not_exist'));
}
/**
* @covers ::xmlToRows
*/
public function testXmlToRowsEmptyFile() : void {
// File system with an empty XML file.
vfsStream::setup('junit_test', NULL, [
'empty.xml' => '',
]);
$this->assertSame([], JUnitConverter::xmlToRows(23, vfsStream::url('junit_test/empty.xml')));
}
/**
* @covers ::xmlElementToRows
*/
public function testXmlElementToRows() : void {
$junit = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest" file="/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php" tests="3" assertions="5" errors="0" failures="0" skipped="0" time="0.215539">
<testcase name="testGetTestClasses" class="Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest" classname="Drupal.Tests.simpletest.Unit.TestDiscoveryTest" file="/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php" line="108" assertions="2" time="0.100787"/>
</testsuite>
</testsuites>
EOD;
$simpletest = [
[
'test_id' => 23,
'test_class' => 'Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest',
'status' => 'pass',
'message' => '',
'message_group' => 'Other',
'function' => 'Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest->testGetTestClasses()',
'line' => 108,
'file' => '/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php',
],
];
$this->assertEquals($simpletest, JUnitConverter::xmlElementToRows(23, new \SimpleXMLElement($junit)));
}
/**
* @covers ::convertTestCaseToSimpletestRow
*/
public function testConvertTestCaseToSimpletestRow() : void {
$junit = <<<EOD
<testcase name="testGetTestClasses" class="Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest" classname="Drupal.Tests.simpletest.Unit.TestDiscoveryTest" file="/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php" line="108" assertions="2" time="0.100787"/>
EOD;
$simpletest = [
'test_id' => 23,
'test_class' => 'Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest',
'status' => 'pass',
'message' => '',
'message_group' => 'Other',
'function' => 'Drupal\\Tests\\simpletest\\Unit\\TestDiscoveryTest->testGetTestClasses()',
'line' => 108,
'file' => '/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php',
];
$this->assertEquals($simpletest, JUnitConverter::convertTestCaseToSimpletestRow(23, new \SimpleXMLElement($junit)));
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
JUnitConverterTest::testConvertTestCaseToSimpletestRow | public | function | @covers ::convertTestCaseToSimpletestRow | ||
JUnitConverterTest::testXmlElementToRows | public | function | @covers ::xmlElementToRows | ||
JUnitConverterTest::testXmlToRowsEmptyFile | public | function | @covers ::xmlToRows | ||
JUnitConverterTest::testXmlToRowsWithErrors | public | function | Tests errors reported. @covers ::xmlToRows |
||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | ||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | ||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | ||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | ||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | ||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | |
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | ||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
UnitTestCase::setUp | protected | function | 358 | ||
UnitTestCase::setUpBeforeClass | public static | function | |||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.