DataCollectorTypeExtension example


    private FormDataCollectorInterface $dataCollector;

    public function __construct(FormDataCollectorInterface $dataCollector)
    {
        $this->dataCollector = $dataCollector;
    }

    protected function loadTypeExtensions(): array
    {
        return [
            new Type\DataCollectorTypeExtension($this->dataCollector),
        ];
    }
}
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormRegistry;
use Symfony\Component\Form\ResolvedFormTypeFactory;

class DataCollectorTypeExtensionTest extends TestCase
{
    private DataCollectorTypeExtension $extension;

    protected function setUp(): void
    {
        $this->extension = new DataCollectorTypeExtension(new FormDataCollector(new FormDataExtractor()));
    }

    public function testGetExtendedType()
    {
        $this->assertEquals(['Symfony\Component\Form\Extension\Core\Type\FormType']$this->extension::getExtendedTypes());
    }

    public function testBuildForm()
    {
        $eventDispatcher = new EventDispatcher();
        $this->assertFalse($eventDispatcher->hasListeners(FormEvents::PRE_SET_DATA));
        
Home | Imprint | This part of the site doesn't use cookies.