DiscoverServiceProvidersTest.php

Same filename and directory in other branches
  1. 9 core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php
  2. 8.9.x core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php
  3. 10 core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php

Namespace

Drupal\Tests\Core\DrupalKernel

File

core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\Core\DrupalKernel;

use Composer\Autoload\ClassLoader;
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.
     *
     * @covers ::discoverServiceProviders
     */
    public function testDiscoverServiceCustom() : void {
        new Settings([
            'container_yamls' => [
                __DIR__ . '/fixtures/custom.yml',
            ],
        ]);
        $kernel = new DrupalKernel('prod', new ClassLoader());
        $kernel->discoverServiceProviders();
        $reflected_yamls = (new \ReflectionObject($kernel))->getProperty('serviceYamls');
        $expect = [
            'app' => [
                'core' => 'core/core.services.yml',
            ],
            'site' => [
                __DIR__ . '/fixtures/custom.yml',
            ],
        ];
        $this->assertSame($expect, $reflected_yamls->getValue($kernel));
    }
    
    /**
     * Tests the exception when container_yamls is not set.
     */
    public function testDiscoverServiceNoContainerYamls() : void {
        new Settings([]);
        $kernel = new DrupalKernel('prod', new ClassLoader());
        $kernel->discoverServiceProviders();
        $reflected_yamls = (new \ReflectionObject($kernel))->getProperty('serviceYamls');
        $expect = [
            'app' => [
                'core' => 'core/core.services.yml',
            ],
            'site' => [],
        ];
        $this->assertSame($expect, $reflected_yamls->getValue($kernel));
    }

}

Classes

Title Deprecated Summary
DiscoverServiceProvidersTest @coversDefaultClass \Drupal\Core\DrupalKernel @group DrupalKernel

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.