News Feed
Jobs Feed
Sections




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

Simon Jodet:
Partial mocks with Mockery
January 15, 2013 @ 09:10:14

Simon Jodet has a new post to his site for the Mockery users out there (a mocking tool used in unit testing) showing how he created his partial object mocks.

I really like atoum and highly recommend it. However, because it's a young project, I have two problems with it: The documentation was really lagging but it's getting there and integration with other tools is poor. [...] And then I stumbled on Mockery. Unlike atoum, it doesn't replace PHPUnit, it just replaces its mocking system with a more elegant, powerful and reliable one. The big plus of Mockery over PHPUnit is that you don't need to have the class to mock to create a mock. [...] But writing partial mocks with Mockery is not obvious.

He illustrates with a "Database" class example containing four methods, only three of which he wants to mock out - dropTable, listTables and getSchema. The fourth method, "reset", is then called directly and the mocked methods are used inside that. The database connection mock is then injected into the Database mock and the test is run. Complete code examples are provided.

0 comments voice your opinion now!
mocks mockery class tutorial phpunit unittest


blog comments powered by Disqus

Similar Posts

Builder.com: Match users to their geo-location with PHP and PEAR Net:Geo

PHP -GTK Community Site: A New Trio of Posts (phpISO, a PHP-GTK book, and Dev Inspector)

NETTUTS.com: How to Write a "Most Popular By Views" WordPress Plugin

The Bakery: Eight New Items (Components, Tutorials & Helpers)

PHPBuilder.com: Harness the Scripting Power of PHP and cURL to Update Facebook


Community Events











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


hack overview release security code series unittest opinion podcast introduction framework symfony2 facebook component language composer hhvm package install application

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