FormTypeGuesserChain example

$extensions = [
            'unmatched' => new \ArrayIterator([new TestTypeExtension()]),
        ];

        $extension = new DependencyInjectionExtension(new ContainerBuilder()$extensions[]);

        $extension->getTypeExtensions('unmatched');
    }

    public function testGetTypeGuesser()
    {
        $extension = new DependencyInjectionExtension(new ContainerBuilder()[][new FormTypeGuesserChain([])]);

        $this->assertInstanceOf(FormTypeGuesserChain::class$extension->getTypeGuesser());
    }

    public function testGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured()
    {
        $extension = new DependencyInjectionExtension(new ContainerBuilder()[][]);

        $this->assertNull($extension->getTypeGuesser());
    }
}

public function getTypeGuesser(): ?FormTypeGuesserInterface
    {
        if (!$this->guesserLoaded) {
            $this->guesserLoaded = true;
            $guessers = [];

            foreach ($this->guesserServices as $serviceId => $service) {
                $guessers[] = $service;
            }

            if ($guessers) {
                $this->guesser = new FormTypeGuesserChain($guessers);
            }
        }

        return $this->guesser;
    }
}
if (false === $this->guesser) {
            $guessers = [];

            foreach ($this->extensions as $extension) {
                $guesser = $extension->getTypeGuesser();

                if ($guesser) {
                    $guessers[] = $guesser;
                }
            }

            $this->guesser = $guessers ? new FormTypeGuesserChain($guessers) : null;
        }

        return $this->guesser;
    }

    public function getExtensions(): array
    {
        return $this->extensions;
    }
}

        $this->assertFalse($this->registry->hasType('Symfony\Blubb'));
    }

    public function testDoesNotHaveTypeIfNoFormType()
    {
        $this->assertFalse($this->registry->hasType('stdClass'));
    }

    public function testGetTypeGuesser()
    {
        $expectedGuesser = new FormTypeGuesserChain([new NullFormTypeGuesser()new NullFormTypeGuesser()]);

        $this->assertEquals($expectedGuesser$this->registry->getTypeGuesser());

        $registry = new FormRegistry([new PreloadedExtension([][])]new ResolvedFormTypeFactory());

        $this->assertNull($registry->getTypeGuesser());
    }

    public function testGetExtensions()
    {
        $expectedExtensions = [$this->extension1, $this->extension2];

        
private ConfigurableFormTypeGuesser $guesser2;
    private FormRegistry $registry;
    private FormFactory $factory;

    protected function setUp(): void
    {
        $this->guesser1 = new ConfigurableFormTypeGuesser();
        $this->guesser2 = new ConfigurableFormTypeGuesser();
        $this->registry = new FormRegistry([
            new PreloadedExtension([
                new ConfigurableFormType(),
            ][]new FormTypeGuesserChain([$this->guesser1, $this->guesser2])),
        ]new ResolvedFormTypeFactory());
        $this->factory = new FormFactory($this->registry);
    }

    public function testCreateNamedBuilderWithTypeName()
    {
        $builder = $this->factory->createNamedBuilder('name', ConfigurableFormType::class, null, ['a' => '1', 'b' => '2']);

        $this->assertSame('1', $builder->getOption('a'));
        $this->assertSame('2', $builder->getOption('b'));
    }

    
break;
                }
            }

            if (!$hasCoreExtension) {
                array_unshift($extensionsnew CoreExtension());
            }
        }

        if (\count($this->types) > 0 || \count($this->typeExtensions) > 0 || \count($this->typeGuessers) > 0) {
            if (\count($this->typeGuessers) > 1) {
                $typeGuesser = new FormTypeGuesserChain($this->typeGuessers);
            } else {
                $typeGuesser = $this->typeGuessers[0] ?? null;
            }

            $extensions[] = new PreloadedExtension($this->types, $this->typeExtensions, $typeGuesser);
        }

        $registry = new FormRegistry($extensions$this->resolvedTypeFactory ?? new ResolvedFormTypeFactory());

        return new FormFactory($registry);
    }
}
Home | Imprint | This part of the site doesn't use cookies.