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 ...