Creating an Interface To a Language's Standard Library?
Posted
by
Nathan Arthur
on Programmers
See other posts from Programmers
or by Nathan Arthur
Published on 2014-06-11T17:01:57Z
Indexed on
2014/06/11
21:38 UTC
Read the original article
Hit count: 211
In the process of learning test-driven development, I've been introduced to dependency injection and the use of interfaces, and have started using these concepts in my own PHP code in order to make it more testable.
There have been times when I've needed to test code that was doing things like calling the PHP time()
function. In order to make these tests predictable, it seemed logical to create an interface to the standard PHP functions I use so that I can mock them out in my tests.
Is this good software design? What are the pros and cons of doing this? I've found myself groaning at how quickly my PHP interface can stick its fingers into everything I do. Is there a better way to make code that relies on PHP-accessed state and functions more testable?
© Programmers or respective owner