Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthias Noback:
Mocking at architectural boundaries: the filesystem and randomness
Mar 06, 2018 @ 15:39:55

Matthias Noback has continued his series of posts covering mocking and testing at the "architectural boundaries" of your application. In this second post he offers two more suggestions of these "edges" where mocking could be useful: filesystem interfaces and randomness.

In a previous article, we discussed "persistence" and "time" as boundary concepts that need mocking by means of dependency inversion: define your own interface, then provide an implementation for it. There were three other topics left to cover: the filesystem, the network and randomness.

He starts with the mocking of the filesystem handling and makes the recommendation of using either vfsStreamor Flysystem to provide an interface that's more easily testable. These libraries abstract away the filesystem and make it easier to mock out the functionality rather than going directly to PHP's filesystem functions. His second example, randomness, is a bit tougher as the output isn't predictable. He still recommends abstracting it out, however, and offers suggestions as to what might be possible to test.

tagged: mocking boarder architecture filesystem randomness series part2

Link: https://matthiasnoback.nl/2018/03/mocking-the-filesystem-and-randomness/


Trending Topics: