ControllerBaseTest.php in Drupal 10
File
core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php
View source
<?php
namespace Drupal\Tests\Core\Controller;
use Drupal\Tests\UnitTestCase;
class ControllerBaseTest extends UnitTestCase {
protected $controllerBase;
protected function setUp() : void {
$this->controllerBase = $this
->getMockForAbstractClass('Drupal\\Core\\Controller\\ControllerBase');
}
public function testGetConfig() {
$config_factory = $this
->getConfigFactoryStub([
'config_name' => [
'key' => 'value',
],
'config_name2' => [
'key2' => 'value2',
],
]);
$container = $this
->createMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container
->expects($this
->once())
->method('get')
->with('config.factory')
->will($this
->returnValue($config_factory));
\Drupal::setContainer($container);
$config_method = new \ReflectionMethod('Drupal\\Core\\Controller\\ControllerBase', 'config');
$config_method
->setAccessible(TRUE);
$config = $config_method
->invoke($this->controllerBase, 'config_name');
$this
->assertEquals('value', $config
->get('key'));
$config = $config_method
->invoke($this->controllerBase, 'config_name2');
$this
->assertEquals('value2', $config
->get('key2'));
}
}