YamlDumper example

class YamlDumperTest extends TestCase
{
    protected static string $fixturesPath;

    public static function setUpBeforeClass(): void
    {
        self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
    }

    public function testDump()
    {
        $dumper = new YamlDumper($container = new ContainerBuilder());

        $this->assertEqualYamlStructure(file_get_contents(self::$fixturesPath.'/yaml/services1.yml')$dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
    }

    public function testAddParameters()
    {
        $container = include self::$fixturesPath.'/containers/container8.php';
        $dumper = new YamlDumper($container);
        $this->assertEqualYamlStructure(file_get_contents(self::$fixturesPath.'/yaml/services8.yml')$dumper->dump(), '->dump() dumps parameters');
    }

    

        return [
            new TwigFilter('yaml_encode', $this->encode(...)),
            new TwigFilter('yaml_dump', $this->dump(...)),
        ];
    }

    public function encode(mixed $input, int $inline = 0, int $dumpObjects = 0): string
    {
        static $dumper;

        $dumper ??= new YamlDumper();

        if (\defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) {
            return $dumper->dump($input$inline, 0, $dumpObjects);
        }

        return $dumper->dump($input$inline, 0, false, $dumpObjects);
    }

    public function dump(mixed $value, int $inline = 0, int $dumpObjects = 0): string
    {
        if (\is_resource($value)) {
            

    public function testConfig($file)
    {
        $fixtures = realpath(__DIR__.'/../Fixtures');
        $container = new ContainerBuilder();
        $container->registerExtension(new \AcmeExtension());
        $loader = new PhpFileLoader($containernew FileLocator(), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()));
        $loader->load($fixtures.'/config/'.$file.'.php');

        $container->compile();

        $dumper = new YamlDumper($container);
        $this->assertStringMatchesFormatFile($fixtures.'/config/'.$file.'.expected.yml', $dumper->dump());
    }

    public static function provideConfig()
    {
        yield ['basic'];
        yield ['object'];
        yield ['defaults'];
        yield ['instanceof'];
        yield ['prototype'];
        yield ['prototype_array'];
        
Home | Imprint | This part of the site doesn't use cookies.