Codeception Unit Testing Model Validation Field by Field


I'm trying to set up a codeception unit test on my application. I have the phalcon module set up and it's running quite nicely. I'm trying to follow the example as laid out here.

In the example it sets the name field with various false entries and then tests each one, before moving on to the next.

I have set up the validation function in my model that does simple prescenceOf validations of a number of fields.

When I run my tests, the first username is null so i get the assertFalse as a "success". Then when I change the username to something "correct" as I have additional validation fields the assertTrue fails because one of the other fields is missing.

I'm probably approaching this from the wrong direction, so I'd really appreciate some examples of how best to complete what I'm trying to do. Any guidance or pointers to documentation/tutorials would be amazing - google doesn't seem to throw much up for my search queries.

Many thanks in advance.

edited Jul '17

Well don't check validation if it returns true/false. More likely check what messages you have after doing validation method, like use Phalcon\Mvc\Model\Message::__set_state For example how it's done in phalcon repo:

Though it's only testing Validation component, though for models it will be similar.