Testing Rating an Idea UseCase

Michael Feathers introduced a definition of legacy code as code without tests. You don't want your code to be legacy just born, do you?

In order to unit test this UseCase object, you decide to start with the easiest part, what happens if the repository is not available? How can we generate such behavior? Do we stop our Redis server while running the unit tests? No. We need to have an object that has such behavior. Let's use a mock object in Listing 9:

class RateIdeaUseCaseTest extends \PHPUnit_Framework_TestCase{    /**     * @test     */    public function whenRepositoryNotAvailableAnExceptionIsThrown()    {        $this->setExpectedException('NotAvailableRepositoryException');        $ideaRepository = new NotAvailableRepository(); $useCase ...

Get Domain-Driven Design in PHP now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.