reverted: --- b/core/tests/Drupal/Tests/UnitTestCase.php +++ a/core/tests/Drupal/Tests/UnitTestCase.php @@ -42,11 +42,6 @@ \Drupal::unsetContainer(); $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); - - // Ensure that tests are in the Drupal\Tests namespace. - if (__NAMESPACE__ != 'Drupal\Tests' && strpos(__NAMESPACE__, 'Drupal\Tests\\', 0) !== 0) { - throw new \Exception('Unit tests must be in the "Drupal\Tests" namespace.'); - } } /** reverted: --- b/core/tests/Drupal/UnitTestCaseTest/UnitTestCaseTest.php +++ /dev/null @@ -1,40 +0,0 @@ -add('Drupal\\Tests', __DIR__); -$loader->add('Drupal\\UnitTestCaseTest', __DIR__); +$loader->add('Drupal\\DrupalStandardsListenerTest', __DIR__); // Scan for arbitrary extension namespaces from core and contrib. $extension_roots = array_merge(array( only in patch2: unchanged: --- a/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php +++ b/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php @@ -16,6 +16,13 @@ class DrupalStandardsListener extends \PHPUnit_Framework_BaseTestListener { /** + * Saves the classes that fail the namespace check. + * + * @var array + */ + protected $namespaceCheckFailedClasses = array(); + + /** * Signals a coding standards failure to the user. * * @param \PHPUnit_Framework_TestCase $test @@ -144,6 +151,24 @@ public function checkValidCoversForTest(\PHPUnit_Framework_TestCase $test) { } /** + * Checks that tests are in the Drupal\Tests namespace. + * + * @param \PHPUnit_Framework_Test $test + * The test where we should insert our test failure. + */ + protected function checkValidNamespaceForTest(\PHPUnit_Framework_Test $test) { + $class = get_class($test); + if (!in_array($class, $this->namespaceCheckFailedClasses) && strpos($class, 'Drupal\Tests\\', 0) !== 0) { + // For the unit test of this method we run endTest() twice, but we don't + // want to run this namespace check a second time as the test failure + // would go uncaught. + $this->namespaceCheckFailedClasses[] = $class; + $test->assertTrue(FALSE, 'Test is not in the Drupal\Tests namespace.'); + } + } + + + /** * {@inheritdoc} */ public function endTest(\PHPUnit_Framework_Test $test, $time) { @@ -152,6 +177,7 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) { // subclasses. if ($test instanceof \PHPUnit_Framework_TestCase) { $this->checkValidCoversForTest($test); + $this->checkValidNamespaceForTest($test); } elseif ($test instanceof \PHPUnit_Framework_TestSuite) { foreach ($test->getGroupDetails() as $tests) {