News Feed
Jobs Feed
Sections




News Archive
feed this:

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

Sebastian Göttschkes' Blog:
Using vsfstream (with symfony2)
April 05, 2012 @ 11:32:50

In this recent post Sebastian Göttschkes shows how to use the vfsStream stream wrapper in a Symfony2 application to create tests that involve the local file system.

I read about vsfstream when skipping through the phpunit docs. Back then, I decided I don't need a virtual file system. Some time later, I had to test classes which read and write files and found myself creating and deleting temporary folders, messing around with nasty errors (like my favourite one where for some reasons tests fail when I don't use @runTestsInSeparateProcesses).

He walks you through the install process, how to register it in the Symfony2 autoloader (so you don't have to include the files each time) and how to include it (via namespace-based loading) in your tests.

0 comments voice your opinion now!
vfsstream symfony2 tutorial filesystem unittest phpunit


VG Tech Blog:
Mocking the File System Using PHPUnit and vfsStream
December 09, 2011 @ 09:40:13

On the VG Tech blog today there's another post related to unit testing (here's one from before) but this time they're talking about mocking the filesystem with vfsStream, a powerful tool that lets you interact with PHP streams as a virtual file system.

This article is about how to mock the file system when writing unit tests, and it will be rather code-heavy. [...] PHPUnit is the de-facto standard for unit testing in PHP projects, and this is what we will be using together with vfsStream in this article.

The include the code for a simple storage driver (VGF_Storage_Driver_Filesystem) to use with vfsStream with "store", "delete" and "get" methods. Also included are examples of using vfsStream to check things like directory existence, if a file exists, or if a file can be read. A few simple assertions are set up in their sample test to check the methods in their "VGF_Storage_Driver_Filesystem" class.

0 comments voice your opinion now!
unittest phpunit vfsstream tutorial filesystem mock


Lars Tesmer's Blog:
How to Unit Test a Class Making Calls to an URL (or the Filesystem) With PHPUnit
September 21, 2011 @ 12:04:47

Lars Tesmer has a suggestion for all of the unit testers out there (you do unit test your code, right?) when needing to test a piece of code that makes a call to something on the file system or a remote resource. Their examples come from tests written against the Assetic codebase.

For our most recent After Work Hacking my co-workers and me decided to write unit tests for the open source project Assetic. That turned out to be a better decision than our last one, yet we still ran into an interesting challenge.

In testing the HttpAsset class from the tool, they came across the problem - a call to a remote/file resource that could not be tested because of a file_get_contents call that depends on an external source. They came up with a few options to try to test this example, some better than others:

  • Give it a real URL to test with
  • Wrap the file_get_contents inside of a new class (ex. a "ContentFetcher")
  • Use vfsStream to mock out the file system in the unit test

In their case, vfsStream couldn't be used due to how the fetch call was made, but the tool can be very handy if you need to mock out an external file system resource.

0 comments voice your opinion now!
phpunit unittest remote url filesystem resource mock vfsstream


Stubbles Blog:
vfsStream 0.1.0 Released
December 27, 2007 @ 11:11:00

On the Stubbles blog, Frank Kleine has posted about the release of a new wrapper class he's developed to go around a virtual file system.

Some minutes ago I released the first version of vfsStream. vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest.

The idea for the class came about when he thought about the use of real databases vs test databases and applied it to file systems. You can grab the latest version from their trac website as well as get more information about known issues and a brief example of its use.

0 comments voice your opinion now!
vfsstream release virtual file system unittest phpunit simpletest database vfsstream release virtual file system unittest phpunit simpletest database



Community Events











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


composer hack overview component release facebook introduction unittest framework package application symfony2 security hhvm example opinion language code install podcast

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