News Feed
Sections




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

VG Tech Blog:
Unit Testing with Streams in PHP
December 08, 2011 @ 09:13:28

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 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 [using "php://memory"]. 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.

There's no specific code examples here, but you can refer to the stream wrappers section of the PHP manual for more details on this and other handy built-in streams. Once created, it can then be used just as any other stream resource can. This could be useful to provide mocks in your testing, replacing any other stream-able resource with a "memory" or "temp" placeholder.

0 comments voice your opinion now!
unittest stream memory temp wrapper mock object


blog comments powered by Disqus

Similar Posts

Nefarious Designs: Object-Oriented PHP Part 4: PHP5's Improved Features

DevShed: Retrieving Information on Several Objects with Destructors in PHP 5

Padraic Brady's Blog: Unit Testing: Multiple Assertions And Lazy/Shallow Testing Are Evil

Robert Basic's Blog: Helping out with Zend Framework 2

Michelangelo van Dam's Blog: Quality Assurance on PHP projects - PHPUnit part 1


Community Events





Don't see your event here?
Let us know!


framework series community tool version release opinion podcast update introduction voicesoftheelephpant language interview composer symfony application security package library laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework