News Feed
Sections




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

James Morris:
PHPUnit Mocking and Method Chaining
July 17, 2013 @ 12:13:02

James Morris has an interesting new post about mocking and method chaining and a discovery he made about the proper use of the "at" method in what his mock objects were expecting.

I've been given the task of unit testing Symfony2's security layer, which at first seems daunting, but in reality with a clever bit of PHPUnit mocking, it's actually quite simple. Symfony2 makes heavy use of method chaining.

He illustrates one way to create the mocks for this chain (one mock returning another) but suggests an alternative - returning an instance of "self" to keep the chain alive. He also includes a bit about the "at" matcher and how, despite what the PHPUnit documentation says, it should be correctly used to handle the response of certain methods in the chained call.

0 comments voice your opinion now!
phpunit mock method chain object tutorial matcher

Link: http://blog.jmoz.co.uk/phpunit-mocking-and-method-chaining

blog comments powered by Disqus

Similar Posts

Andrea Giammarchi's Blog: PHP Serialization And Recursion Demystified

NetTuts.com: Basic Functional Testing With Symfony 2's Crawler

Gary Hokin: An Introduction to Zend Framework 2 for the Zend Framework 1 Developer - Part 1

Matthew Turland's Blog: Unit Tests and Code Coverage with PHPT

Jason Fox: Use the Accept Header to Set Your Return Data With Zend Framework 2


Community Events

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


opinion api extension laravel symfony2 version application example series release library performance testing introduction community voicesoftheelephpant framework interview php7 podcast

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