YamlFileLoaderTest.php 1.08 KB
Newer Older
1 2 3 4 5 6 7
<?php

namespace Drupal\Tests\Core\DependencyInjection;

use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\YamlFileLoader;
8
use Drupal\Tests\UnitTestCase;
9 10 11 12 13 14
use org\bovigo\vfs\vfsStream;

/**
 * @coversDefaultClass \Drupal\Core\DependencyInjection\YamlFileLoader
 * @group DependencyInjection
 */
15
class YamlFileLoaderTest extends UnitTestCase {
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    FileCacheFactory::setPrefix('example');
  }

  public function testParseDefinitionsWithProvider() {
    $yml = <<<YAML
services:
  example_service:
    class: \Drupal\Core\ExampleClass
YAML;

    vfsStream::setup('drupal', NULL, [
      'modules/example/example.yml' => $yml,
    ]);

    $builder = new ContainerBuilder();
    $yaml_file_loader = new YamlFileLoader($builder);
    $yaml_file_loader->load('vfs://drupal/modules/example/example.yml');

    $this->assertEquals(['_provider' => [['provider' => 'example']]], $builder->getDefinition('example_service')->getTags());
  }

}