News Feed
Sections




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

Till Klampaeckel's Blog:
RFC Mocking protected methods
June 16, 2011 @ 13:48:33

Till Klampaeckel has a new post to his blog today looking at the method he's found (through some help from others) to be able to mock out protected methods in his unit tests.

I wrote a couple tests for a small CouchDB access wrapper today. But when I wrote the implementation itself, I realized that my class setup depends on an actual CouchDB server being available and here my journey began.

It was his first experience trying to mock out parts of a class, and he found it a bit difficult to use even after reading this article from Sebastian Bergmann. He ended up, as a first solution, making a "fake" (a term from Ruby testing) that just returned the basic JSON string of an error. Thanks to comments on the post, though, he was able to come up with a more correct solution using getMock() to create a stub and apply an expects() to his "makeRequest" method.

0 comments voice your opinion now!
mock protected method unittest phpunit tutorial


blog comments powered by Disqus

Similar Posts

VG Tech Blog: Mocking the File System Using PHPUnit and vfsStream

DeveloperTutorials.com: AJAX and PHP Form Processing

NetTuts.com: Refactoring Legacy Code: Part 1 - The Golden Master

NetTuts.com: Deciphering Testing Jargon

Idrish Laxmidhar's Blog: How to send mail from Localhost with XAMPP and mercury/32


Community Events

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


podcast extension language introduction interview video security version opinion unittest library api release voicesoftheelephpant php7 community framework series laravel laravel5

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