NullFormTypeGuesser example

/** * @author Bernhard Schussek <bschussek@gmail.com> */
class FormRegistryTest extends TestCase
{
    private FormRegistry $registry;
    private TestExtension $extension1;
    private TestExtension $extension2;

    protected function setUp(): void
    {
        $this->extension1 = new TestExtension(new NullFormTypeGuesser());
        $this->extension2 = new TestExtension(new NullFormTypeGuesser());
        $this->registry = new FormRegistry([
            $this->extension1,
            $this->extension2,
        ]new ResolvedFormTypeFactory());
    }

    public function testGetTypeFromExtension()
    {
        $type = new FooType();
        $this->extension2->addType($type);

        
$registry = $this->registry->getValue($factory);
        $extensions = $registry->getExtensions();

        $this->assertCount(1, $extensions);
        $this->assertTrue($extensions[0]->hasType($this->type::class));
        $this->assertNull($extensions[0]->getTypeGuesser());
    }

    public function testAddTypeGuesser()
    {
        $factoryBuilder = new FormFactoryBuilder();
        $factoryBuilder->addTypeGuesser(new NullFormTypeGuesser());

        $factory = $factoryBuilder->getFormFactory();
        $registry = $this->registry->getValue($factory);
        $extensions = $registry->getExtensions();

        $this->assertCount(1, $extensions);
        $this->assertNotNull($extensions[0]->getTypeGuesser());
    }
}
Home | Imprint | This part of the site doesn't use cookies.