News Feed
Sections




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

SitePoint PHP Blog:
Mock your Test Dependencies with Mockery
June 26, 2014 @ 14:26:58

The SitePoint PHP blog has a new post today by Peter Nijssen showing how to use a library that's an alternative to the internal PHPUnit mock handling. The post shows you how to use Mockery to test your applications and abstract out any outside dependencies.

Although not everyone is doing it yet, testing your application is one of the most essential parts of being a developer. Unit tests are the most common tests to run. With unit tests, you can check if a class behaves exactly like you intended it too. Sometimes, you are using a third party service within your application and it's hard to get everything set up to get this unit tested. That's exactly when mocking comes into play.

He starts with a brief introduction to the concept of mocking before getting into his examples. He shows how to get it installed (via Composer) and how to add it as a test listener to your PHPUnit configuration file. He then gets into an actual example: mocking out an external API dependency for a weather service. He shows a simple one-method mock example as well as a more complex example using a more randomized result rather than just a static one.

0 comments voice your opinion now!
mock unittest phpunit mockery tool introduction tutorial

Link: http://www.sitepoint.com/mock-test-dependencies-mockery/

blog comments powered by Disqus

Similar Posts

DevShed: Building a Complete Web Searching Class with Yahoo Web Services and PHP 5

DZone.com: Codeigniter and Object-Oriented PHP: Two Guides

PHPBuilder.com: Using SPL Iterators in PHP to Interact with Different Data Types

Codeception.com: Testing Emails in PHP. Part 1: PHPUnit

WeberDev.com: PHP 101 (part 11) - Sinfully Simple (SimpleXML)


Community Events





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


install threedevsandamaybe community language laravel code library configure developer introduction list interview podcast wordpress series unittest release homestead application api

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