diff --git a/core/lib/Drupal/Core/Test/JUnitListener.php b/core/lib/Drupal/Core/Test/JUnitListener.php
index 08dbf352..5260c8ac 100644
--- a/core/lib/Drupal/Core/Test/JUnitListener.php
+++ b/core/lib/Drupal/Core/Test/JUnitListener.php
@@ -62,7 +62,6 @@ class JUnitListener implements TestListener {
public function __construct() {
$this->document = new \DOMDocument('1.0', 'UTF-8');
$this->document->formatOutput = TRUE;
-
$this->root = $this->document->createElement('testsuites');
$this->document->appendChild($this->root);
}
@@ -78,11 +77,7 @@ public function __destruct() {
}
/**
- * An error occurred.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \Throwable $t
- * @param float $time
+ * {@inheritdoc}
*/
public function addError(Test $test, \Throwable $t, float $time): void {
$this->doAddFault($test, $t, $time, 'error');
@@ -90,11 +85,7 @@ public function addError(Test $test, \Throwable $t, float $time): void {
}
/**
- * A warning occurred.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \PHPUnit\Framework\Warning $e
- * @param float $time
+ * {@inheritdoc}
*/
public function addWarning(Test $test, Warning $e, float $time): void {
$this->doAddFault($test, $e, $time, 'warning');
@@ -102,11 +93,7 @@ public function addWarning(Test $test, Warning $e, float $time): void {
}
/**
- * A failure occurred.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \PHPUnit\Framework\AssertionFailedError $e
- * @param float $time
+ * {@inheritdoc}
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void {
$this->doAddFault($test, $e, $time, 'failure');
@@ -114,42 +101,28 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
}
/**
- * Incomplete test.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \Throwable $t
- * @param float $time
+ * {@inheritdoc}
*/
public function addIncompleteTest(Test $test, \Throwable $t, float $time): void {
$this->doAddSkipped($test, 'incomplete');
}
/**
- * Risky test.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \Throwable $t
- * @param float $time
+ * {@inheritdoc}
*/
public function addRiskyTest(Test $test, \Throwable $t, float $time): void {
$this->doAddSkipped($test, 'risky');
}
/**
- * Skipped test.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \Throwable $t
- * @param float $time
+ * {@inheritdoc}
*/
public function addSkippedTest(Test $test, \Throwable $t, float $time): void {
$this->doAddSkipped($test, 'skipped');
}
/**
- * A testsuite started.
- *
- * @param \PHPUnit\Framework\TestSuite $suite
+ * {@inheritdoc}
*/
public function startTestSuite(TestSuite $suite): void {
$testSuite = $this->document->createElement('testsuite');
@@ -184,9 +157,7 @@ public function startTestSuite(TestSuite $suite): void {
}
/**
- * A testsuite ended.
- *
- * @param \PHPUnit\Framework\TestSuite $suite
+ * {@inheritdoc}
*/
public function endTestSuite(TestSuite $suite): void {
$properties = [
@@ -216,9 +187,7 @@ public function endTestSuite(TestSuite $suite): void {
}
/**
- * A test started.
- *
- * @param \PHPUnit\Framework\Test $test
+ * {@inheritdoc}
*/
public function startTest(Test $test): void {
$testCase = $this->document->createElement('testcase');
@@ -242,10 +211,7 @@ public function startTest(Test $test): void {
}
/**
- * A test ended.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param float $time
+ * {@inheritdoc}
*/
public function endTest(Test $test, float $time): void {
if ($test instanceof TestCase) {
diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist
index fbc1e519..89b3c2ea 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -56,7 +56,6 @@
-
diff --git a/core/tests/Drupal/Tests/Listeners/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/DrupalListener.php
index 0b288bce..b4f34f93 100644
--- a/core/tests/Drupal/Tests/Listeners/DrupalListener.php
+++ b/core/tests/Drupal/Tests/Listeners/DrupalListener.php
@@ -2,10 +2,13 @@
namespace Drupal\Tests\Listeners;
+use Drupal\Core\Test\JUnitListener;
+use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;
+use PHPUnit\Framework\Warning;
use PHPUnit\Util\Test as UtilTest;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
@@ -50,6 +53,13 @@ class DrupalListener implements TestListener {
*/
private $symfonyListener;
+ /**
+ * The wrapped Drupal JUnit test listener.
+ *
+ * @var \Drupal\Core\Test\JUnitListener
+ */
+ private $jUnitListener;
+
/**
* Constructs the DrupalListener object.
*/
@@ -57,12 +67,48 @@ public function __construct() {
$this->symfonyListener = new SymfonyTestsListener();
}
+ /**
+ * {@inheritdoc}
+ */
+ public function addError(Test $test, \Throwable $t, float $time): void {
+ $this->getJUnitListener()->addError($test, $t, $time);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addWarning(Test $test, Warning $e, float $time): void {
+ $this->getJUnitListener()->addWarning($test, $t, $time);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addFailure(Test $test, AssertionFailedError $e, float $time): void {
+ $this->getJUnitListener()->addFailure($test, $t, $time);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addIncompleteTest(Test $test, \Throwable $t, float $time): void {
+ $this->getJUnitListener()->addIncompleteTest($test, $t, $time);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addRiskyTest(Test $test, \Throwable $t, float $time): void {
+ $this->getJUnitListener()->addRiskyTest($test, $t, $time);
+ }
+
/**
* {@inheritdoc}
*/
public function startTestSuite(TestSuite $suite): void {
$this->symfonyListener->startTestSuite($suite);
$this->registerErrorHandler();
+ $this->getJUnitListener()->startTestSuite($suite);
}
/**
@@ -70,6 +116,7 @@ public function startTestSuite(TestSuite $suite): void {
*/
public function addSkippedTest(Test $test, \Throwable $t, float $time): void {
$this->symfonyListener->addSkippedTest($test, $t, $time);
+ $this->getJUnitListener()->addSkippedTest($test, $t, $time);
}
/**
@@ -106,6 +153,7 @@ public function startTest(Test $test): void {
if ($class->hasProperty('modules') && !$class->getProperty('modules')->isProtected()) {
@trigger_error('The ' . get_class($test) . '::$modules property must be declared protected. See https://www.drupal.org/node/2909426', E_USER_DEPRECATED);
}
+ $this->getJUnitListener()->startTest($test);
}
/**
@@ -127,6 +175,7 @@ public function endTest(Test $test, float $time): void {
$this->symfonyListener->endTest($test, $time);
$this->componentEndTest($test, $time);
$this->standardsEndTest($test, $time);
+ $this->getJUnitListener()->endTest($test, $time);
if (isset($symfony_error_handler)) {
// If this test listener has added the Symfony error handler then it needs
// to be removed.
@@ -138,4 +187,21 @@ public function endTest(Test $test, float $time): void {
$this->removeErrorHandler();
}
+ /**
+ * Returns the JUnit listener instance.
+ *
+ * We cannot add a to phpunit.xml or in the constructor here,
+ * since the JUnit listener throws a deprecation that would not be possible
+ * to silence, so we lazy instantiate here when needed.
+ *
+ * @return \PHPUnit\Framework\TestListener
+ * The JUnit listener.
+ */
+ private function getJUnitListener(): TestListener {
+ if (!$this->jUnitListener) {
+ $this->jUnitListener = new JUnitListener();
+ }
+ return $this->jUnitListener;
+ }
+
}