News Feed
Sections




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

PHPMaster.com:
An Introduction to Mock Object Testing
July 20, 2012 @ 17:18:06

In this new tutorial on PHPMaster.com Jose Asuncion walks you through the use of mock objects in your unit testing.

If you are part of a development team, more often than not your code will also depend on code written by your teammates. But what if their code isn't available at the moment - say, your teammate hasn't finished writing it yet? Or, what if the code you need requires other external dependencies that are hard to set up? And what if you cannot test code because of other factors beyond your control? Will you just hang around, do nothing, and wait until your team is done or when everything is in place? Of course not! In this this article, I'll illustrate how to write code that works around this problem with dependencies.

He starts off by making a case for using mock objects and having them replace things that either aren't finished or depends on things that are hard to replicate (like external dependencies). He includes some example code showing them in use in a PHPUnit-based test and how to use its own mocking abilities so you don't have to manually make mock classes yourself.

0 comments voice your opinion now!
mock unittest introduction phpunit framework object


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Building Web Apps with the Limonade PHP Framework

Nick Halstead's Blog: 10 Reasons why PHP is still very much alive

Zend Developer Zone: PHP Security Tip #16 (Keep Frameworks Up-to-Date)

SitePoint PHP Blog: What to Expect from Yii 2.0

Jakub Zalas' Blog: Mocking Symfony Container services in Behat scenarios with Mockery


Community Events

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


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

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