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

DZone.com:
A Mockery Review
May 09, 2011 @ 18:05:14

On the Web Builder Zone (a part of DZone.com) there's a recent post from Giorgio Sironi reviewing the Mockery library, a mock object framework created by Padraic Brady.

Mockery is a mock object framework (more properly Test Double framework) from @padraicb, independent from testing frameworks like PHPUnit. It can be used to quickly prepare Mocks, Stubs and other Test Doubles to use inside your unit tests. I've tried Mockery via a PEAR installation and I must say its expressive power is higher than that of PHPUnit mocking system. However, it may be too powerful for effective usage.

He talks about some of the features that are in Mockery that aren't in PHPUnit like alternative expectations, recording of the expected calls and the mocking of non-existent methods. He notes that it can be too overwhelming at times, though, with so many features that may or may not be useful for the large majority of testers. He includes some sample code showing a set of five tests on a simple class implementing an interface.

tagged: mockery testdoubles unittest mock object

Link:

Chris Hartjes' Blog:
Testing Web Services in Zend Framework 1.x
May 03, 2011 @ 14:20:45

In a new post to his blog Chris Hartjes shares a technique he figured out for testing web services in Zend Framework 1.x - in his case, a remote application he wanted to mock out with test doubles that would give different responses based on the parameters given.

Reading the existing PHPUnit documentation did not provide me with enough hints on how to solve this particular problem, so while I dug around duckduckgoing for a solution I asked Twitter for help. One blog post and 3 tweets later, I had the underpinnings for my test. Check it out. A walk-through is probably required in order to explain what I did.

The sample test (code included in the post) sets up a mock object to abstract the service connection, loads in some fixture data for the different responses (based on request) and an "expectation object" for the GET request on the mock object. This object and the data is then passed to a handler that responds with the right dataset. The example code is here on github in two methods - testGetTracks and setMultipleMatching.

tagged: testing unittest webservice zendframework testdoubles mockobjects

Link:


Trending Topics: