Skip to content

Commit 575f8fb

Browse files
committed
do not mock the validator in form type tests
1 parent bfceeb9 commit 575f8fb

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

form/unit_testing.rst

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,19 @@ allows you to return a list of extensions to register::
182182
namespace Tests\AppBundle\Form\Type;
183183

184184
// ...
185-
use AppBundle\Form\Type\TestedType;
186185
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
187-
use Symfony\Component\Form\Form;
188-
use Symfony\Component\Validator\ConstraintViolationList;
189-
use Symfony\Component\Validator\Mapping\ClassMetadata;
190-
use Symfony\Component\Validator\Validator\ValidatorInterface;
186+
use Symfony\Component\Validator\Validation;
191187

192188
class TestedTypeTest extends TypeTestCase
193189
{
194-
private $validator;
195-
196190
protected function getExtensions()
197191
{
198-
$this->validator = $this->createMock(ValidatorInterface::class);
199-
// use getMock() on PHPUnit 5.3 or below
200-
// $this->validator = $this->getMock(ValidatorInterface::class);
201-
$this->validator
202-
->method('validate')
203-
->will($this->returnValue(new ConstraintViolationList()));
204-
$this->validator
205-
->method('getMetadataFor')
206-
->will($this->returnValue(new ClassMetadata(Form::class)));
192+
$validator = Validation::createValidator();
193+
194+
// or if you also need to read constraints from annotations
195+
$validator = Validation::createValidatorBuilder()
196+
->enableAnnotationMapping()
197+
->getValidator();
207198

208199
return [
209200
new ValidatorExtension($this->validator),

0 commit comments

Comments
 (0)