News Feed
Sections




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

NetTuts.com:
Mockery A Better Way
November 22, 2012 @ 12:06:02

On NetTuts.com there's a new tutorial posted showing you how to use Mockery in your unit testing as an alternative to the built-in mocking tools of something like PHPUnit.

Mockery is a PHP extension that offers a superior mocking experience, particularly when compared to PHPUnit. While PHPUnit's mocking framework is powerful, Mockery offers a more natural language with a Hamcrest-like set of matchers. In this article, I'll compare the two mocking frameworks and highlight the best features of Mockery.

He walks you through the installation of Mockery and includes the code for a sample PHPUnit test that creates a Mockery instance and mocks out a class object for testing. He moves on to more examples including:

  • Adding expects for method calls (single and multiple)
  • Returning values from the methods
  • Calling multiple methods
  • Returning different things based on parameters
  • Partial mocks
  • Handling constructor parameters
0 comments voice your opinion now!
mockery unittest library phpunit mock object tutorial


blog comments powered by Disqus

Similar Posts

Tony Bibbs' Blog: HOWTO: Deploy Your Application Using PEAR

ProDevTips: Sorting 2D-arrays in PHP - anectodes and reflections

Till's Blog: Nginx+PHP+FastCGI: Testing your web application with bleeding edge PHP

IBM developerWorks: What's new in PHP V5.2, Part 4: Using the new ZIP extension

Web Development Blog: PHP Mail Scripts using SMTP transport, a guide for beginners


Community Events

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


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

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