class ContainerBuilderTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest
- 8.9.x core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest
- 10 core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest
@coversDefaultClass \Drupal\Core\DependencyInjection\ContainerBuilder @group DependencyInjection
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\DependencyInjection\ContainerBuilderTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ContainerBuilderTest
File
-
core/
tests/ Drupal/ Tests/ Core/ DependencyInjection/ ContainerBuilderTest.php, line 16
Namespace
Drupal\Tests\Core\DependencyInjectionView source
class ContainerBuilderTest extends UnitTestCase {
/**
* @covers ::get
*/
public function testGet() : void {
$container = new ContainerBuilder();
$container->register('bar', 'Drupal\\Tests\\Core\\DependencyInjection\\Fixture\\BarClass');
$result = $container->get('bar');
$this->assertInstanceOf(BarClass::class, $result);
}
/**
* @covers ::setParameter
*/
public function testSetParameterException() : void {
$container = new ContainerBuilder();
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Parameter names must be lowercase: Buzz');
$container->setParameter('Buzz', 'buzz');
}
/**
* @covers ::register
*/
public function testRegister() : void {
$container = new ContainerBuilder();
$service = $container->register('bar');
$this->assertTrue($service->isPublic());
}
/**
* @covers ::setDefinition
*/
public function testSetDefinition() : void {
// Test a service with public set to true.
$container = new ContainerBuilder();
$definition = new Definition();
$definition->setPublic(TRUE);
$service = $container->setDefinition('foo', $definition);
$this->assertTrue($service->isPublic());
// Test a service with public set to false.
$definition = new Definition();
$definition->setPublic(FALSE);
$service = $container->setDefinition('foo', $definition);
$this->assertFalse($service->isPublic());
}
/**
* @covers ::setAlias
*/
public function testSetAlias() : void {
$container = new ContainerBuilder();
$container->register('bar');
$alias = $container->setAlias('foo', 'bar');
$this->assertTrue($alias->isPublic());
}
/**
* Tests serialization.
*/
public function testSerialize() : void {
$container = new ContainerBuilder();
$this->expectException(\AssertionError::class);
serialize($container);
}
/**
* Tests constructor and resource tracking disabling.
*
* This test runs in a separate process to ensure the aliased class does not
* affect any other tests.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testConstructor() : void {
class_alias(TestInterface::class, 'Symfony\\Component\\Config\\Resource\\ResourceInterface');
$container = new ContainerBuilder();
$this->assertFalse($container->isTrackingResources());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ContainerBuilderTest::testConstructor | public | function | Tests constructor and resource tracking disabling. | |
ContainerBuilderTest::testGet | public | function | @covers ::get | |
ContainerBuilderTest::testRegister | public | function | @covers ::register | |
ContainerBuilderTest::testSerialize | public | function | Tests serialization. | |
ContainerBuilderTest::testSetAlias | public | function | @covers ::setAlias | |
ContainerBuilderTest::testSetDefinition | public | function | @covers ::setDefinition | |
ContainerBuilderTest::testSetParameterException | public | function | @covers ::setParameter | |
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::setUp | protected | function | 355 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.