Although this class works it is impossible to unit test due to two different dependencies being instantiated rather than injected.
This is a great way to spot tightly coupled code that is just aching for a bit of DI. If you can see an object getting newed up inside a method... inject it instead! π―
First of all we use Mockery to mock our account class.
I tend to eschew the use of mocking libraries and just roll my own test doubles. It stops people arguing with me about which one to use... π€£
How to write testable code
Of course, the best way to write testable code - to absolutely guarantee that it's testable - is to write the tests first. π
Good article - thanks for sharing it!
This is a great way to spot tightly coupled code that is just aching for a bit of DI. If you can see an object getting newed up inside a method... inject it instead! π―
I tend to eschew the use of mocking libraries and just roll my own test doubles. It stops people arguing with me about which one to use... π€£
Of course, the best way to write testable code - to absolutely guarantee that it's testable - is to write the tests first. π
Glad you liked the post !
Yup - if I see βnewβ anywhere in a PR you can bet Iβll be investigating to see if it should be refactored (it almost always should)
Maybe Iβll do a TDD one in the future :)