8000 do not mock the validator in form type tests · symfony/symfony-docs@272e479 · GitHub
[go: up one dir, main page]

Skip to content

Commit 272e479

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

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

form/unit_testing.rst

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,31 +182,22 @@ 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 [
209-
new ValidatorExtension($this->validator),
200+
new ValidatorExtension($validator),
210201
];
211202
}
212203

0 commit comments

Comments
 (0)
0