Commit 0a65cd60 authored by alexpott's avatar alexpott
Browse files

Issue #3118477 by mondrake, Mile23: RegistryTest, RegistryLegacyTest both...

Issue #3118477 by mondrake, Mile23: RegistryTest, RegistryLegacyTest both define the same class, use mock instead
parent d3b2a6f6
<?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"
);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Theme\RegistryLegacyTest.
*/
namespace Drupal\Tests\Core\Theme;
use Drupal\Core\Theme\ActiveTheme;
......@@ -21,9 +16,9 @@
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 @@ protected function setUp() {
$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 @@ public function testGetLegacyThemeFunctionRegistryForModule() {
}
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();
}
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Theme\RegistryTest.
*/
namespace Drupal\Tests\Core\Theme;
use Drupal\Core\Theme\ActiveTheme;
......@@ -18,9 +13,9 @@
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 @@ public function testPostProcessExtension($defined_functions, $hooks, $expected)
->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 @@ public function providerTestPostProcessExtension() {
}
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment