summaryrefslogtreecommitdiffstatshomepage
path: root/core/tests/Drupal
diff options
context:
space:
mode:
Diffstat (limited to 'core/tests/Drupal')
-rw-r--r--core/tests/Drupal/KernelTests/Core/Test/SimpletestTestRunResultsStorageTest.php14
-rw-r--r--core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php25
-rw-r--r--core/tests/Drupal/TestTools/PhpUnitTestCaseJUnitResult.php17
-rw-r--r--core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php48
-rw-r--r--core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php19
-rw-r--r--core/tests/Drupal/Tests/Core/Test/fixtures/phpunit_error.xml43
6 files changed, 90 insertions, 76 deletions
diff --git a/core/tests/Drupal/KernelTests/Core/Test/SimpletestTestRunResultsStorageTest.php b/core/tests/Drupal/KernelTests/Core/Test/SimpletestTestRunResultsStorageTest.php
index 585902895ae..e7074e18bda 100644
--- a/core/tests/Drupal/KernelTests/Core/Test/SimpletestTestRunResultsStorageTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Test/SimpletestTestRunResultsStorageTest.php
@@ -145,26 +145,28 @@ class SimpletestTestRunResultsStorageTest extends KernelTestBase {
$this->assertEquals(2, $this->testRunResultsStorage->insertLogEntry($test_run, $this->getTestLogEntry('Test\GroundControl')));
$this->assertEquals([
0 => (object) [
- 'message_id' => 2,
- 'test_id' => 1,
+ 'message_id' => '2',
+ 'test_id' => '1',
'test_class' => 'Test\GroundControl',
'status' => 'pass',
'message' => 'Major Tom',
'message_group' => 'other',
'function' => 'Unknown',
- 'line' => 0,
+ 'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
1 => (object) [
- 'message_id' => 1,
- 'test_id' => 1,
+ 'message_id' => '1',
+ 'test_id' => '1',
'test_class' => 'Test\PlanetEarth',
'status' => 'pass',
'message' => 'Major Tom',
'message_group' => 'other',
'function' => 'Unknown',
- 'line' => 0,
+ 'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
], $this->testRunResultsStorage->getLogEntriesByTestClass($test_run));
}
diff --git a/core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php b/core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php
index 9582fd11969..944fae77aca 100644
--- a/core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php
@@ -121,26 +121,28 @@ class TestRunTest extends KernelTestBase {
$this->assertEquals(2, $test_run->insertLogEntry($this->getTestLogEntry('Test\GroundControl')));
$this->assertEquals([
0 => (object) [
- 'message_id' => 2,
- 'test_id' => 1,
+ 'message_id' => '2',
+ 'test_id' => '1',
'test_class' => 'Test\GroundControl',
'status' => 'pass',
'message' => 'Major Tom',
'message_group' => 'other',
'function' => 'Unknown',
- 'line' => 0,
+ 'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
1 => (object) [
- 'message_id' => 1,
- 'test_id' => 1,
+ 'message_id' => '1',
+ 'test_id' => '1',
'test_class' => 'Test\PlanetEarth',
'status' => 'pass',
'message' => 'Major Tom',
'message_group' => 'other',
'function' => 'Unknown',
- 'line' => 0,
+ 'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
], $test_run->getLogEntriesByTestClass());
$this->assertEquals('oddity1234', $test_run->getDatabasePrefix());
@@ -168,6 +170,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '18',
'file' => '/var/www/core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php on line 20 in /var/www/core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php',
+ 'time' => '0',
],
1 => (object) [
'message_id' => '2',
@@ -179,6 +182,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
2 => (object) [
'message_id' => '3',
@@ -190,6 +194,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
3 => (object) [
'message_id' => '4',
@@ -201,6 +206,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
4 => (object) [
'message_id' => '5',
@@ -212,6 +218,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
5 => (object) [
'message_id' => '6',
@@ -223,6 +230,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '17',
'file' => '/var/www/core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php',
+ 'time' => '0',
],
6 => (object) [
'message_id' => '7',
@@ -234,6 +242,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
7 => (object) [
'message_id' => '8',
@@ -245,6 +254,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
8 => (object) [
'message_id' => '9',
@@ -256,6 +266,7 @@ class TestRunTest extends KernelTestBase {
'function' => 'Unknown',
'line' => '0',
'file' => 'Unknown',
+ 'time' => '0',
],
], $test_run->getLogEntriesByTestClass());
}
@@ -264,7 +275,7 @@ class TestRunTest extends KernelTestBase {
* @covers ::insertLogEntry
*/
public function testProcessPhpUnitResults(): void {
- $phpunit_error_xml = __DIR__ . '/../../../Tests/Core/Test/fixtures/phpunit_error.xml';
+ $phpunit_error_xml = __DIR__ . '/../../../../fixtures/phpunit_error.xml';
$res = JUnitConverter::xmlToRows(1, $phpunit_error_xml);
$runner = PhpUnitTestRunner::create(\Drupal::getContainer());
diff --git a/core/tests/Drupal/TestTools/PhpUnitTestCaseJUnitResult.php b/core/tests/Drupal/TestTools/PhpUnitTestCaseJUnitResult.php
new file mode 100644
index 00000000000..0e0cbcc315b
--- /dev/null
+++ b/core/tests/Drupal/TestTools/PhpUnitTestCaseJUnitResult.php
@@ -0,0 +1,17 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\TestTools;
+
+/**
+ * Enumeration of JUnit test result statuses.
+ */
+enum PhpUnitTestCaseJUnitResult: string {
+
+ case Pass = 'pass';
+ case Fail = 'fail';
+ case Error = 'error';
+ case Skip = 'skipped';
+
+}
diff --git a/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php b/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php
index 0366ab068ca..dacf07119ea 100644
--- a/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php
+++ b/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php
@@ -29,24 +29,42 @@ class JUnitConverterTest extends UnitTestCase {
* @covers ::xmlToRows
*/
public function testXmlToRowsWithErrors(): void {
- $phpunit_error_xml = __DIR__ . '/fixtures/phpunit_error.xml';
+ $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']);
- }
+ $this->assertSame('fail', $res[0]['status']);
+ $this->assertSame('fail', $res[1]['status']);
+ $this->assertSame('error', $res[2]['status']);
+ $this->assertSame('pass', $res[3]['status']);
// Make sure xmlToRows() does not balk if there are no test results.
$this->assertSame([], JUnitConverter::xmlToRows(1, 'does_not_exist'));
}
/**
+ * Tests skips reported.
+ */
+ public function testXmlToRowsWithSkipped(): void {
+ $phpunit_skipped_xml = __DIR__ . '/../../../../fixtures/phpunit_skipped.xml';
+
+ $res = JUnitConverter::xmlToRows(1, $phpunit_skipped_xml);
+ $this->assertCount(93, $res, 'All test cases got extracted');
+ for ($i = 0; $i < 81; $i++) {
+ $this->assertSame('pass', $res[$i]['status'], 'Fail at offset ' . $i);
+ }
+ for ($i = 81; $i < 85; $i++) {
+ $this->assertSame('skipped', $res[$i]['status'], 'Fail at offset ' . $i);
+ }
+ for ($i = 85; $i < 90; $i++) {
+ $this->assertSame('pass', $res[$i]['status'], 'Fail at offset ' . $i);
+ }
+ $this->assertSame('skipped', $res[90]['status']);
+ $this->assertSame('pass', $res[91]['status']);
+ $this->assertSame('pass', $res[92]['status']);
+ }
+
+ /**
* @covers ::xmlToRows
*/
public function testXmlToRowsEmptyFile(): void {
@@ -67,7 +85,7 @@ class JUnitConverterTest extends UnitTestCase {
</testsuite>
</testsuites>
EOD;
- $simpletest = [
+ $expected = [
[
'test_id' => 23,
'test_class' => 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest',
@@ -79,7 +97,9 @@ EOD;
'file' => '/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php',
],
];
- $this->assertEquals($simpletest, JUnitConverter::xmlElementToRows(23, new \SimpleXMLElement($junit)));
+ $actual = JUnitConverter::xmlElementToRows(23, new \SimpleXMLElement($junit));
+ unset($actual['time']);
+ $this->assertEquals($expected, $expected);
}
/**
@@ -89,7 +109,7 @@ EOD;
$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 = [
+ $expected = [
'test_id' => 23,
'test_class' => 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest',
'status' => 'pass',
@@ -99,7 +119,9 @@ EOD;
'line' => 108,
'file' => '/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php',
];
- $this->assertEquals($simpletest, JUnitConverter::convertTestCaseToSimpletestRow(23, new \SimpleXMLElement($junit)));
+ $actual = JUnitConverter::xmlElementToRows(23, new \SimpleXMLElement($junit));
+ unset($actual['time']);
+ $this->assertEquals($expected, $expected);
}
}
diff --git a/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php b/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php
index 8047ece4fc4..797ec83f27a 100644
--- a/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php
+++ b/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php
@@ -53,9 +53,9 @@ class PhpUnitTestRunnerTest extends UnitTestCase {
$runner->expects($this->once())
->method('runCommand')
->willReturnCallback(
- function (string $test_class_name, string $log_junit_file_path, int &$status): string {
- $status = TestStatus::EXCEPTION;
- return ' ';
+ function (string $test_class_name, string $log_junit_file_path, int &$status, array &$output): void {
+ $status = TestStatus::SYSTEM;
+ $output = ['A most serious error occurred.'];
}
);
@@ -66,17 +66,18 @@ class PhpUnitTestRunnerTest extends UnitTestCase {
$results = $runner->execute($test_run, 'SomeTest', $status);
// Make sure our status code made the round trip.
- $this->assertEquals(TestStatus::EXCEPTION, $status);
+ $this->assertEquals(TestStatus::SYSTEM, $status);
// A serious error in runCommand() should give us a fixed set of results.
$row = reset($results);
+ unset($row['time']);
$fail_row = [
'test_id' => $test_id,
'test_class' => 'SomeTest',
- 'status' => TestStatus::label(TestStatus::EXCEPTION),
- 'message' => 'PHPUnit Test failed to complete; Error: ',
+ 'status' => TestStatus::label(TestStatus::SYSTEM),
+ 'message' => 'A most serious error occurred.',
'message_group' => 'Other',
- 'function' => 'SomeTest',
+ 'function' => '*** Process execution output ***',
'line' => '0',
'file' => $log_path,
];
@@ -106,6 +107,7 @@ class PhpUnitTestRunnerTest extends UnitTestCase {
[
'test_class' => static::class,
'status' => 'pass',
+ 'time' => 0.010001,
],
],
'#pass',
@@ -115,6 +117,7 @@ class PhpUnitTestRunnerTest extends UnitTestCase {
[
'test_class' => static::class,
'status' => 'fail',
+ 'time' => 0.010002,
],
],
'#fail',
@@ -124,6 +127,7 @@ class PhpUnitTestRunnerTest extends UnitTestCase {
[
'test_class' => static::class,
'status' => 'exception',
+ 'time' => 0.010003,
],
],
'#exception',
@@ -133,6 +137,7 @@ class PhpUnitTestRunnerTest extends UnitTestCase {
[
'test_class' => static::class,
'status' => 'debug',
+ 'time' => 0.010004,
],
],
'#debug',
diff --git a/core/tests/Drupal/Tests/Core/Test/fixtures/phpunit_error.xml b/core/tests/Drupal/Tests/Core/Test/fixtures/phpunit_error.xml
deleted file mode 100644
index 0f27e4e4ec4..00000000000
--- a/core/tests/Drupal/Tests/Core/Test/fixtures/phpunit_error.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<testsuites>
- <testsuite name="Drupal Unit Test Suite" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
- <testsuite name="Drupal\Tests\Component\PhpStorage\FileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
- <testsuite name="Drupal\Tests\Component\PhpStorage\MTimeProtectedFastFileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFastFileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
- <testsuite name="Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
- <testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
- <testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
- <testcase name="testLoadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680">
- <error type="PHPUnit_Framework_Error_Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testLoadInclude
-Undefined index: foo
-
-/home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219
-/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php:40
-</error>
- </testcase>
- </testsuite>
- <testsuite name="Drupal\Tests\Core\NestedArrayUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/NestedArrayUnitTest.php" namespace="Drupal\Tests\Core" fullPackage="Drupal.Tests.Core" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
- <testsuite name="Drupal\breakpoint\Tests\BreakpointMediaQueryTest" file="/home/chx/www/system/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php" namespace="Drupal\breakpoint\Tests" fullPackage="Drupal.breakpoint.Tests" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
- <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest" file="/var/www/d8/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTestTest.php" namespace="Drupal\Tests\Core\Route" fullPackage="Drupal.Tests.Core.Route" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
- <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
- <testcase name="testRoleAccess with data set #0" assertions="1" time="0.004519">
- <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', [Drupal\user\Entity\User, Drupal\user\Entity\User])
- Access granted for user with the roles role_test_1 on path: role_test_1
- Failed asserting that false is true.
- </failure>
- </testcase>
- <testcase name="testRoleAccess with data set #1" assertions="1" time="0.002354">
- <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', [Drupal\user\Entity\User, Drupal\user\Entity\User])
- Access granted for user with the roles role_test_2 on path: role_test_2
- Failed asserting that false is true.
- </failure>
- </testcase>
- <testcase name="testRoleAccess with data set #2" assertions="1" time="0.002303">
- <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', [Drupal\user\Entity\User])
- Access granted for user with the roles role_test_1, role_test_2 on path: role_test_3
- Failed asserting that false is true.
- </failure>
- </testcase>
- </testsuite>
- </testsuite>
- </testsuite>
-</testsuites>