Unit testing with streams in PHP
Using the memory/temporary stream provided by php:// stream wrapper you can create a stream with read and write access directly to RAM or to a temporary file.
This gives you the possibilty to write unit tests that does not rely on a specific file, resource or stream, but rather on data provided by the test itself.
Creating a memory stream is easy; $fp = fopen('php://memory', 'r+');. Now you have a resource that can be used and manipulated just like any other stream or file.
1 comments
VG Tech Blog: Unit Testing with Streams in PHP | Scripting4You Blog
[...] On the VG Tech blog today there's a new post from André Roaldseth about using PHPUnit to test PHP streams, basing the assertions on the data rather than the functionality itself. Using the [...]