Issue #3118477 by mondrake, Mile23: RegistryTest, RegistryLegacyTest both define the same class, use mock instead
parent
d3b2a6f654
commit
0a65cd6076
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Test;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @group TestSuites
|
||||
* @group Test
|
||||
*/
|
||||
class PhpUnitCliTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Ensure that the test suites are able to discover tests without incident.
|
||||
*/
|
||||
public function testPhpUnitListTests() {
|
||||
// Generate the list of tests for all the tests the suites can discover.
|
||||
// The goal here is to successfully generate the list, without any
|
||||
// duplicate namespace errors or so forth. This keeps us from committing
|
||||
// tests which don't break under run-tests.sh, but do break under the
|
||||
// phpunit test runner tool.
|
||||
$process = new Process('vendor/bin/phpunit --configuration core --verbose --list-tests');
|
||||
$process->setWorkingDirectory($this->root)
|
||||
->setTimeout(300)
|
||||
->setIdleTimeout(300);
|
||||
$process->run();
|
||||
$this->assertEquals(0, $process->getExitCode(),
|
||||
'COMMAND: ' . $process->getCommandLine() . "\n" .
|
||||
'OUTPUT: ' . $process->getOutput() . "\n" .
|
||||
'ERROR: ' . $process->getErrorOutput() . "\n"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Theme\RegistryLegacyTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Theme;
|
||||
|
||||
use Drupal\Core\Theme\ActiveTheme;
|
||||
|
@ -21,9 +16,9 @@ use Drupal\Tests\UnitTestCase;
|
|||
class RegistryLegacyTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The tested theme registry.
|
||||
* The mocked theme registry.
|
||||
*
|
||||
* @var \Drupal\Tests\Core\Theme\TestRegistry
|
||||
* @var \Drupal\Core\Theme\Registry|PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
|
@ -69,13 +64,6 @@ class RegistryLegacyTest extends UnitTestCase {
|
|||
*/
|
||||
protected $themeManager;
|
||||
|
||||
/**
|
||||
* The list of functions that get_defined_functions() should provide.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $functions = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -92,14 +80,6 @@ class RegistryLegacyTest extends UnitTestCase {
|
|||
$this->setupTheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function tearDown() {
|
||||
parent::tearDown();
|
||||
static::$functions = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getting legacy theme function registry data defined by a module.
|
||||
*
|
||||
|
@ -152,29 +132,18 @@ class RegistryLegacyTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
protected function setupTheme() {
|
||||
$this->registry = new TestRegistry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization);
|
||||
$this->registry = $this->getMockBuilder(Registry::class)
|
||||
->setMethods(['getPath'])
|
||||
->setConstructorArgs([$this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization])
|
||||
->getMock();
|
||||
$this->registry->expects($this->any())
|
||||
->method('getPath')
|
||||
->willReturnCallback(function ($module) {
|
||||
if ($module == 'theme_legacy_test') {
|
||||
return 'core/modules/system/tests/modules/theme_legacy_test';
|
||||
}
|
||||
});
|
||||
$this->registry->setThemeManager($this->themeManager);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestRegistry extends Registry {
|
||||
|
||||
protected function getPath($module) {
|
||||
if ($module == 'theme_legacy_test') {
|
||||
return 'core/modules/system/tests/modules/theme_legacy_test';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Core\Theme;
|
||||
|
||||
use Drupal\Tests\Core\Theme\RegistryLegacyTest;
|
||||
|
||||
/**
|
||||
* Overrides get_defined_functions() with a configurable mock.
|
||||
*/
|
||||
function get_defined_functions() {
|
||||
return RegistryLegacyTest::$functions ?: \get_defined_functions();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Theme\RegistryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Theme;
|
||||
|
||||
use Drupal\Core\Theme\ActiveTheme;
|
||||
|
@ -18,9 +13,9 @@ use Drupal\Tests\UnitTestCase;
|
|||
class RegistryTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The tested theme registry.
|
||||
* The mocked theme registry.
|
||||
*
|
||||
* @var \Drupal\Tests\Core\Theme\TestRegistry
|
||||
* @var \Drupal\Core\Theme\Registry|PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
|
@ -190,7 +185,7 @@ class RegistryTest extends UnitTestCase {
|
|||
->method('getModuleList')
|
||||
->willReturn([]);
|
||||
|
||||
$class = new \ReflectionClass(TestRegistry::class);
|
||||
$class = new \ReflectionClass(Registry::class);
|
||||
$reflection_method = $class->getMethod('postProcessExtension');
|
||||
$reflection_method->setAccessible(TRUE);
|
||||
$reflection_method->invokeArgs($this->registry, [&$hooks, $theme->reveal()]);
|
||||
|
@ -476,22 +471,22 @@ class RegistryTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
protected function setupTheme() {
|
||||
$this->registry = new TestRegistry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization);
|
||||
$this->registry = $this->getMockBuilder(Registry::class)
|
||||
->setMethods(['getPath'])
|
||||
->setConstructorArgs([$this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization])
|
||||
->getMock();
|
||||
$this->registry->expects($this->any())
|
||||
->method('getPath')
|
||||
->willReturnCallback(function ($module) {
|
||||
if ($module == 'theme_test') {
|
||||
return 'core/modules/system/tests/modules/theme_test';
|
||||
}
|
||||
});
|
||||
$this->registry->setThemeManager($this->themeManager);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestRegistry extends Registry {
|
||||
|
||||
protected function getPath($module) {
|
||||
if ($module == 'theme_test') {
|
||||
return 'core/modules/system/tests/modules/theme_test';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Core\Theme;
|
||||
|
||||
use Drupal\Tests\Core\Theme\RegistryTest;
|
||||
|
|
Loading…
Reference in New Issue