Closed
Description
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