News Feed
Sections




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

Sebastian Bergmann's Blog:
Stubbing Hard-Coded Dependencies
February 16, 2010 @ 11:55:51

Sebastian Bergmann has a new post to his blog (part of a series on testing techniques for testing that difficult code) about the hard-coded dependencies required by your code and how to stub them for easier testing.

A mock object can be used anywhere in the program where the program expects an object of the mocked class. However, this only works as long as the object can be passed into the context where the original object is used.

Ideally this wouldn't be a problem - handled correctly, dependency injection would make it a non-issue. But, because it has been known to happen, PHPUnit gives you the ability, via the set_new_overload method, to capture that object definition and mock it with a reference to another method in the test class.

0 comments voice your opinion now!
stub unittest dependency hardcode phpunit


blog comments powered by Disqus

Similar Posts

Sam Hennessy's Blog: A Dependency Injection for PHP Manifesto – Part 2 (Why I Want It)

Mike Naberezny's Blog: Wrapping PHP Functions for Testability

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 12)

Sebastian Göttschkes' Blog: Extending the Testclass for Unittests

Brandon Savage's Blog: Peer Review: Testable Code And Architecture


Community Events





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


symfony conference series security introduction language voicesoftheelephpant opinion framework release laravel artisanfiles list interview tool podcast community composer version library

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