[Dev] Add unit test to PickPostalCodeType

This commit is contained in:
Julien Fastré 2022-10-06 22:06:45 +02:00
parent 9aae36556b
commit dea217a670

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Repository\PostalCodeRepositoryInterface;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionClass;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\TypeTestCase;
@ -31,19 +32,21 @@ final class PickPostalCodeTypeTest extends TypeTestCase
public function testSubmitValidData(): void
{
$form = $this->factory->create(PickPostalCodeType::class, null);
$builder = $this->factory->createBuilder(FormType::class, ['postal_code' => null]);
$builder->add('postal_code', PickPostalCodeType::class);
$form = $builder->getForm();
$form->submit(['1']);
$form->submit(['postal_code' => '1']);
$this->assertTrue($form->isSynchronized());
$this->assertEquals(1, $form->getData()->getId());
$this->assertEquals(1, $form['postal_code']->getData()->getId());
}
protected function getExtensions()
{
$postalCodeRepository = $this->prophesize(PostalCodeRepositoryInterface::class);
$postalCodeRepository->find(Argument::type('string'))
$postalCodeRepository->find(Argument::any())
->will(static function ($args) {
$postalCode = new PostalCode();
$reflectionClass = new ReflectionClass($postalCode);