In writing PHPSPEC tests for a Zend Framework 2 application, I'm left wondering how far to 'dig'. Consider this very simple case:
A DomainService (Domain in the URL sense of the word) should be able to list all Foo objects, works.
Making heads/tails of the test is not simple. This DomainService is fed via DI with a DomainMapper. This DomainMapper is a Doctrine Mapper that transforms MySQL rows into Doctrine Entities. In theory, would I not want to cover that my code can:
- instantiate the DomainService (but this is done through ZF2 Factories -- I'm completely bypassing the Factory process in using phpspec's let). Does this tailspin into a separate test for the Factory, that needs a functional service locator object?
- test that it can find all Foo objects, but this means invoking Doctrine and running an SQL query. The test shouldn't be database dependent I assume, we wouldn't want external data to modify the test. But what then should I test, that it successfully returns an empty array? Semantic query errors could create empty array conditions that are failures. Do we simply accept that tests don't cover this?
Where do you draw the line? Testing DI'ed services that interact with databases can't automatically be off-limits?