addTypeExtension example

$this->expectException(InvalidArgumentException::class);
        $this->registry->getType('stdClass');
    }

    public function testGetTypeWithTypeExtensions()
    {
        $type = new FooType();
        $ext1 = new FooTypeBarExtension();
        $ext2 = new FooTypeBazExtension();

        $this->extension2->addType($type);
        $this->extension1->addTypeExtension($ext1);
        $this->extension2->addTypeExtension($ext2);

        $resolvedFormType = $this->registry->getType(FooType::class);

        $this->assertInstanceOf(ResolvedFormType::class$resolvedFormType);
        $this->assertSame($type$resolvedFormType->getInnerType());
        $this->assertSame([$ext1$ext2]$resolvedFormType->getTypeExtensions());
    }

    public function testGetTypeConnectsParent()
    {
        
use Symfony\Component\Form\Tests\Fixtures\LazyChoiceTypeExtension;

class ExtendedChoiceTypeTest extends TestCase
{
    /** * @dataProvider provideTestedTypes */
    public function testChoicesAreOverridden($type)
    {
        ChoiceTypeExtension::$extendedType = $type;
        $factory = Forms::createFormFactoryBuilder()
            ->addTypeExtension(new ChoiceTypeExtension())
            ->getFormFactory()
        ;

        $choices = $factory->create($type, null, ['choice_loader' => null])->createView()->vars['choices'];

        $this->assertCount(2, $choices);
        $this->assertSame('A', $choices[0]->label);
        $this->assertSame('a', $choices[0]->value);
        $this->assertSame('B', $choices[1]->label);
        $this->assertSame('b', $choices[1]->value);
    }

    

        foreach ($typeExtension::getExtendedTypes() as $extendedType) {
            $this->typeExtensions[$extendedType][] = $typeExtension;
        }

        return $this;
    }

    public function addTypeExtensions(array $typeExtensions)static
    {
        foreach ($typeExtensions as $typeExtension) {
            $this->addTypeExtension($typeExtension);
        }

        return $this;
    }

    public function addTypeGuesser(FormTypeGuesserInterface $typeGuesser)static
    {
        $this->typeGuessers[] = $typeGuesser;

        return $this;
    }

    
Home | Imprint | This part of the site doesn't use cookies.