class ControllerBaseTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Controller/ControllerBaseTest.php \Drupal\KernelTests\Core\Controller\ControllerBaseTest
- 11.x core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest
- 10 core/tests/Drupal/KernelTests/Core/Controller/ControllerBaseTest.php \Drupal\KernelTests\Core\Controller\ControllerBaseTest
- 10 core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest
- 8.9.x core/tests/Drupal/Tests/Core/Controller/ControllerBaseTest.php \Drupal\Tests\Core\Controller\ControllerBaseTest
Tests that the base controller class.
@group Controller
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Controller\ControllerBaseTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ControllerBaseTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Controller/ ControllerBaseTest.php, line 12
Namespace
Drupal\Tests\Core\ControllerView source
class ControllerBaseTest extends UnitTestCase {
/**
* The tested controller base class.
*
* @var \Drupal\Core\Controller\ControllerBase|\PHPUnit\Framework\MockObject\MockObject
*/
protected $controllerBase;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->controllerBase = $this->getMockForAbstractClass('Drupal\\Core\\Controller\\ControllerBase');
}
/**
* Tests the config method.
*/
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')
->willReturn($config_factory);
\Drupal::setContainer($container);
$config_method = new \ReflectionMethod('Drupal\\Core\\Controller\\ControllerBase', 'config');
$config_method->setAccessible(TRUE);
// Call config twice to ensure that the container is just called once.
$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'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.