Skip to content

Testings Types from the Service Container doesn't find dependencies #36462

@rgrassian

Description

@rgrassian

Symfony version(s) affected: 4.4.7

Description
In my case I can't test a type with a dependency, I get the following error :

ArgumentCountError: Too few arguments to function Symfony\Bridge\Doctrine\Form\Type\DoctrineType::__construct()

How to reproduce

class ContractCommercialGestureNewTypeTest extends TypeTestCase
{
    /**
     * @var CommercialGestureRepository|MockObject
     */
    protected $commercialGestureRepository;

    /**
     * @return void
     */
    protected function setUp(): void
    {
        $this->commercialGestureRepository = $this->createMock(CommercialGestureRepository::class);

        parent::setUp();
    }

    /**
     * @return void
     */
    public function testSubmitForm(): void
    {
        $contractCommercialGestureToCompare = new ContractCommercialGesture();
        $form = $this->factory->create(ContractCommercialGestureNewType::class, $contractCommercialGestureToCompare);
    }

    /**
     * @return array<FormExtensionInterface>
     */
    protected function getExtensions(): array
    {
        $type = new ContractCommercialGestureNewType($this->commercialGestureRepository);

        return [
            new PreloadedExtension([$type], []),
        ];
    }
}

Possible Solution

Additional context
The construct of my type :

    public function __construct(CommercialGestureRepository $commercialGestureRepository)
    {
        $this->commercialGestureRepository = $commercialGestureRepository;
    }

The link of the documentation :
https://symfony.com/doc/current/form/unit_testing.html#testings-types-from-the-service-container

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy