Skip to content

Instantly share code, notes, and snippets.

@blackandred
Created July 31, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackandred/be5ab9c96aa7a75b9b8c60e30dae0f46 to your computer and use it in GitHub Desktop.
Save blackandred/be5ab9c96aa7a75b9b8c60e30dae0f46 to your computer and use it in GitHub Desktop.
Symfony: Mock Symfony validator to return always true in isValid() for functional testing
<?php
protected function mockFormValidationToReturnValid(): void
{
$form = $this->createMock(FormInterface::class);
$form->method('isValid')->willReturn(true);
$factory = $this->createMock(FormFactoryInterface::class);
$factory->method('create')->willReturn(FormInterface::class)->willReturn($form);
$this->getContainer()->set('form.factory', $factory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment