News Feed
Sections




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

Chris Hartjes:
Test Spies and Mockery
December 31, 2013 @ 09:39:30

Chris Hartjes has a new post today looking at using test spies with Mockery, the alternative mocking framework to PHPUnit's own built-in functionality. Test spies are a feature that allows you to replace certain functions and methods of already created objects to help make mocking functionality easier.

While recording some screencasts I was struggling to figure out how to get PHPUnit's built-in object mocking tools to allow me to create what is known as a "test spy". I talk about them briefly in my PHPUnit Cookbook but I think that what I wanted to do in this instance was beyond what PHPUnit could give me.

He works through what he tried with the built-in PHPUnit mocking and found that it wasn't using the objects he provided as expected. He shifted over to Mockery and created a working version using the "shouldReceive" and "with" methods to handle the checks (spies) on the objects correctly.

0 comments voice your opinion now!
unittest spies phpunit mockery example

Link: http://www.littlehart.net/atthekeyboard/2013/12/27/test-spies-and-mockery

blog comments powered by Disqus

Similar Posts

Felix Geisendorfer's Blog: My new best friend - PHP's create_function()

Ibuildings Blog: Zend_Paginator: First Impressions

Justin Silverton\'s Blog: Using sqlite and php

Jani Hartikainen's Blog: Zend_Acl part 1: Misconceptions and simple ACLs

KillerPHP Blog: PHP Interfaces: when and why you should use them instead of classes?


Community Events





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


extension opinion version community configure interview unittest voicesoftheelephpant symfony series list composer release podcast laravel api introduction language conference install

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