DiscoverServiceProvidersTest.php 1.58 KB
Newer Older
1
2
3
4
<?php

namespace Drupal\Tests\Core\DrupalKernel;

5
use Composer\Autoload\ClassLoader;
6
7
8
9
10
11
12
13
14
15
16
17
18
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\Core\DrupalKernel
 * @group DrupalKernel
 */
class DiscoverServiceProvidersTest extends UnitTestCase {

  /**
   * Tests discovery with user defined container yaml.
   *
19
   * @covers ::discoverServiceProviders
20
21
   */
  public function testDiscoverServiceCustom() {
22
23
    new Settings([
      'container_yamls' => [
24
        __DIR__ . '/fixtures/custom.yml',
25
26
      ],
    ]);
27

28
    $kernel = new DrupalKernel('prod', new ClassLoader());
29
30
    $kernel->discoverServiceProviders();

31
32
33
    $reflected_yamls = (new \ReflectionObject($kernel))->getProperty('serviceYamls');
    $reflected_yamls->setAccessible(TRUE);

34
35
    $expect = [
      'app' => [
36
        'core' => 'core/core.services.yml',
37
38
      ],
      'site' => [
39
        __DIR__ . '/fixtures/custom.yml',
40
41
      ],
    ];
42
    $this->assertSame($expect, $reflected_yamls->getValue($kernel));
43
44
45
46
47
48
49
  }

  /**
   * Tests the exception when container_yamls is not set.
   */
  public function testDiscoverServiceNoContainerYamls() {
    new Settings([]);
50
    $kernel = new DrupalKernel('prod', new ClassLoader());
51
    $kernel->discoverServiceProviders();
52

53
54
55
    $reflected_yamls = (new \ReflectionObject($kernel))->getProperty('serviceYamls');
    $reflected_yamls->setAccessible(TRUE);

56
57
58
59
    $expect = [
      'app' => [
        'core' => 'core/core.services.yml',
      ],
60
      'site' => [],
61
    ];
62
    $this->assertSame($expect, $reflected_yamls->getValue($kernel));
63
64
65
  }

}