I do some unit test in all my doctrine entities in a Symfony2 Project. I test setter/getter in a class UserTest and also setter/getter with db persistance in a class UserDbTest, all the files are in an Entity Folder under the test Folder
is it a good think to testing both, and what’s the best place to put the Db classes?
Thx for your advice!
If you do not have custom database logic (which you should not have) in your
Entityclasses you don’t have to create unit and functional tests. Doctrine is tested, i.e. it is ensured thatpersist/flushwork correctly and you do not have to duplicate these tests.However, if you want to test, for example, if your queries work correctly I personally have a
XYManagerclass (whereXYis the name of the entity), where I put all custom database logic (and further abstraction) in it. My approach was inspired by the FOSUserBundle (see their UserManager).In my projects both the
Entityand theEntityMangerclasses are in theEntityfolder of the bundle and the tests for these classes are in theTests/Entityfolder. Since functional tests take a lot longer than unit tests I separate them using the@groupannotation of PHPUnit. I add@group unitto all tests that do not require a database and are not ofWebTestCaseand@group functionalto all tests that do require a database or are ofWebTestCase.If I want to execute only the unit tests I can do
and
will only execute the functional tests.
will execute both functional and unit tests.