DEV Community

Discussion on: How to Make Your Laravel App More Testable

Collapse
 
mmp4k profile image
Marcin

Unfortunately, that test is incorrect and it's very fragile.

The test has to pass if you change implementation. So, if I change class NewsletterSubscriptionService to another one, a method handle to something else then the test will fail, whenever an email is saved correctly.

Collapse
 
ashallendesign profile image
Ash Allen

Hi Marcin, thanks for the comment.

I do agree that this test can be seen as being fragile, but this example is just a simple one that we can use to explain the concept of dependency injection and mocking. In a real-life scenario, I'd have used an interface instead to decouple the code so that we could switch out the implementation further down the line. I didn't want to throw too much at the readers at once though and scare them away haha :)