YamlFileLoader example

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
        $this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
    }

    public static function loaderProvider()
    {
        return [
            [
                [
                    new LoaderChain([
                        new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
                        new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
                    ]),
                ],
            ],
            [
                [
                    new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
                    new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
                ],
            ],
        ];
    }

    
'constant' => \PHP_EOL,
        ];

        $this->assertEquals($expected$actual, '->load() converts XML values to PHP ones');
    }

    public function testLoadImports()
    {
        $container = new ContainerBuilder();
        $resolver = new LoaderResolver([
            new IniFileLoader($containernew FileLocator(self::$fixturesPath.'/ini')),
            new YamlFileLoader($containernew FileLocator(self::$fixturesPath.'/yml')),
            $loader = new XmlFileLoader($containernew FileLocator(self::$fixturesPath.'/xml')),
        ]);
        $loader->setResolver($resolver);
        $loader->load('services4.xml');

        $actual = $container->getParameterBag()->all();
        $expected = [
            'a_string' => 'a string',
            'foo' => 'bar',
            'values' => [
                0,
                
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
        $container->compile();
    }

    private function loadFromFile(ContainerBuilder $container$file$format)
    {
        $locator = new FileLocator(__DIR__.'/Fixtures/'.$format);

        $loader = match ($format) {
            'php' => new PhpFileLoader($container$locator),
            'xml' => new XmlFileLoader($container$locator),
            'yml' => new YamlFileLoader($container$locator),
        };

        $loader->load($file.'.'.$format);
    }
}
public function testDumpDecoratedServices()
    {
        $container = include self::$fixturesPath.'/containers/container34.php';
        $dumper = new YamlDumper($container);
        $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services34.yml', $dumper->dump());
    }

    public function testDumpLoad()
    {
        $container = new ContainerBuilder();
        $loader = new YamlFileLoader($containernew FileLocator(self::$fixturesPath.'/yaml'));
        $loader->load('services_dump_load.yml');

        $this->assertEquals([new Reference('bar', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)]$container->getDefinition('foo')->getArguments());

        $dumper = new YamlDumper($container);
        $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_dump_load.yml', $dumper->dump());
    }

    public function testInlineServices()
    {
        $container = new ContainerBuilder();
        

        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid "invalid locale" locale.');
        $loader = $this->createMock(LoaderInterface::class);
        $translator = $this->getTranslator($loader['cache_dir' => $this->tmpDir], 'loader', TranslatorWithInvalidLocale::class);

        $translator->trans('foo');
    }

    public function testLoadResourcesWithoutCaching()
    {
        $loader = new YamlFileLoader();
        $resourceFiles = [
            'fr' => [
                __DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
            ],
        ];

        $translator = $this->getTranslator($loader['resource_files' => $resourceFiles], 'yml');
        $translator->setLocale('fr');

        $this->assertEquals('rĂ©pertoire', $translator->trans('folder'));
    }

    

    public function getLoaders(): array
    {
        $loaders = [];

        foreach ($this->xmlMappings as $xmlMapping) {
            $loaders[] = new XmlFileLoader($xmlMapping);
        }

        foreach ($this->yamlMappings as $yamlMappings) {
            $loaders[] = new YamlFileLoader($yamlMappings);
        }

        foreach ($this->methodMappings as $methodName) {
            $loaders[] = new StaticMethodLoader($methodName);
        }

        if ($this->enableAnnotationMapping) {
            $loaders[] = new AnnotationLoader($this->annotationReader);
        }

        return array_merge($loaders$this->loaders);
    }

class YamlFileLoaderTest extends TestCase
{
    use ContextMappingTestTrait;

    private YamlFileLoader $loader;
    private ClassMetadata $metadata;

    protected function setUp(): void
    {
        $this->loader = new YamlFileLoader(__DIR__.'/../../Fixtures/serialization.yml');
        $this->metadata = new ClassMetadata(GroupDummy::class);
    }

    public function testInterface()
    {
        $this->assertInstanceOf(LoaderInterface::class$this->loader);
    }

    public function testLoadClassMetadataReturnsTrueIfSuccessful()
    {
        $this->assertTrue($this->loader->loadClassMetadata($this->metadata));
    }
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class YamlFrameworkExtensionTest extends FrameworkExtensionTestCase
{
    protected function loadFromFile(ContainerBuilder $container$file)
    {
        $loader = new YamlFileLoader($containernew FileLocator(__DIR__.'/Fixtures/yml'));
        $loader->load($file.'.yml');
    }
}


    /** * @dataProvider getContainerParameterForRoute */
    public function testCacheValidityWithContainerParameters($parameter)
    {
        $cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);

        try {
            $container = new Container();
            $container->set('routing.loader', new YamlFileLoader(new FileLocator(__DIR__.'/Fixtures')));

            $container->setParameter('parameter.condition', $parameter);

            $router = new Router($container, 'with_condition.yaml', [
                'debug' => true,
                'cache_dir' => $cacheDir,
            ]);

            $resourceCheckers = [
                new ContainerParametersResourceChecker($container),
            ];

            

class YamlFilesLoader extends FilesLoader
{
    public function getFileLoaderInstance(string $file): LoaderInterface
    {
        return new YamlFileLoader($file);
    }
}
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_1')->getTags());
    $this->assertEquals('example_service_1', $builder->getAlias('example_service_2')->__toString());
    $this->assertTrue($builder->getDefinition('example_service_1')->isPublic());
    $this->assertFalse($builder->getDefinition('example_private_service')->isPublic());
    $builder->compile();
    $this->assertTrue($builder->has('example_service_1'));
    $this->assertFalse($builder->has('example_private_service'));
    $this->assertTrue($builder->has('Drupal\Core\ExampleClass'));
    $this->assertSame('Drupal\Core\ExampleClass', $builder->getDefinition('Drupal\Core\ExampleClass')->getClass());
  }
$container->compile();
        $dumper = new PhpDumper($container);

        $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_env_in_id.php', $dumper->dump());
    }

    public function testEnvParameter()
    {
        $rand = mt_rand();
        putenv('Baz='.$rand);
        $container = new ContainerBuilder();
        $loader = new YamlFileLoader($containernew FileLocator(self::$fixturesPath.'/yaml'));
        $loader->load('services26.yml');
        $container->setParameter('env(json_file)', self::$fixturesPath.'/array.json');
        $container->compile();
        $dumper = new PhpDumper($container);

        $this->assertStringEqualsFile(self::$fixturesPath.'/php/services26.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_EnvParameters', 'file' => self::$fixturesPath.'/php/services26.php', 'inline_factories' => false, 'inline_class_loader' => false]));

        require self::$fixturesPath.'/php/services26.php';
        $container = new \Symfony_DI_PhpDumper_Test_EnvParameters();
        $this->assertSame($rand$container->getParameter('baz'));
        $this->assertSame([123, 'abc']$container->getParameter('json'));
        
$instanceof = [];
            $bundleLoader->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    private function createContainerLoader(ContainerBuilder $container, string $env): DelegatingLoader
    {
        $buildDir = $container->getParameter('kernel.build_dir');
        $locator = new FileLocator();
        $resolver = new LoaderResolver([
            new XmlFileLoader($container$locator$env),
            new YamlFileLoader($container$locator$env),
            new IniFileLoader($container$locator$env),
            new PhpFileLoader($container$locator$envnew ConfigBuilderGenerator($buildDir)),
            new GlobFileLoader($container$locator$env),
            new DirectoryLoader($container$locator$env),
            new ClosureLoader($container$env),
        ]);

        return new DelegatingLoader($resolver);
    }
}
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class YamlCompleteConfigurationTest extends CompleteConfigurationTestCase
{
    protected function getLoader(ContainerBuilder $container)
    {
        return new YamlFileLoader($containernew FileLocator(__DIR__.'/Fixtures/yml'));
    }

    protected function getFileExtension()
    {
        return 'yml';
    }
}

class YamlFilesLoader extends FilesLoader
{
    public function getFileLoaderInstance(string $file): LoaderInterface
    {
        return new YamlFileLoader($file);
    }
}
Home | Imprint | This part of the site doesn't use cookies.