Symfony2 & TDD – Testing Entity Validation Constraints

I am trying to learn TDD and have had some problems to get started with TDD in Symfony 2 but I have finally stumbled on a solution (I hope, correct me if I am doing something wrong please).

All we need to do is to use the ValidatorFactory that comes with Symfony like in the example below.

        $validator = ValidatorFactory::buildDefault()->getValidator();
        $errors = $validator->validate($e);
        $this->assertEquals(0, count($errors));

I found the solution here so a big thank you to Kasheen.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>