class ControllerBaseTest
Same name in this branch
- 11.x core/tests/Drupal/KernelTests/Core/Controller/ControllerBaseTest.php \Drupal\KernelTests\Core\Controller\ControllerBaseTest
Same name in other branches
- 9 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
- 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
Tests that the base controller class.
@group Controller
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- 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 14
Namespace
Drupal\Tests\Core\ControllerView source
class ControllerBaseTest extends UnitTestCase {
/**
* The tested controller base class.
*/
protected StubControllerBase $controllerBase;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->controllerBase = new StubControllerBase();
}
/**
* Tests the config method.
*/
public function testGetConfig() : void {
$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(StubControllerBase::class, 'config');
// 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'));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ControllerBaseTest::$controllerBase | protected | property | The tested controller base class. | |
ControllerBaseTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
ControllerBaseTest::testGetConfig | public | function | Tests the config method. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.