026154da70876348c01189553c12dfc9fffdd0ab
[yaffs-website] / web / core / tests / Drupal / Tests / Core / DependencyInjection / ContainerBuilderTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\DependencyInjection;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\Tests\Core\DependencyInjection\Fixture\BarClass;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\DependencyInjection\ContainerBuilder
11  * @group DependencyInjection
12  */
13 class ContainerBuilderTest extends UnitTestCase {
14
15   /**
16    * @covers ::get
17    */
18   public function testGet() {
19     $container = new ContainerBuilder();
20     $container->register('bar', 'Drupal\Tests\Core\DependencyInjection\Fixture\BarClass');
21
22     $result = $container->get('bar');
23     $this->assertTrue($result instanceof BarClass);
24   }
25
26   /**
27    * @covers ::set
28    */
29   public function testSet() {
30     $container = new ContainerBuilder();
31     $class = new BarClass();
32     $container->set('bar', $class);
33     $this->assertEquals('bar', $class->_serviceId);
34   }
35
36   /**
37    * @covers ::set
38    */
39   public function testSetException() {
40     $container = new ContainerBuilder();
41     $class = new BarClass();
42     $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar');
43     $container->set('Bar', $class);
44   }
45
46   /**
47    * @covers ::setParameter
48    */
49   public function testSetParameterException() {
50     $container = new ContainerBuilder();
51     $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz');
52     $container->setParameter('Buzz', 'buzz');
53   }
54
55   /**
56    * @covers ::register
57    */
58   public function testRegisterException() {
59     $container = new ContainerBuilder();
60     $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar');
61     $container->register('Bar');
62   }
63
64   /**
65    * Tests serialization.
66    */
67   public function testSerialize() {
68     $container = new ContainerBuilder();
69     $this->setExpectedException(\AssertionError::class);
70     serialize($container);
71   }
72
73 }