 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Johannes Schluter's Blog: Class posing and overloading the "new" operator
by Chris Cornutt January 07, 2010 @ 10:24:16
In this recent post to his blog Johannes Schluter talks about a method he's suggested for testing objects in unit tests - overriding the "new" operator to replace specific classes with mocks.
Two years ago at some conference I had a conversation with Sebastian about the need for a way to overload the new operator in PHP so, probably, bad designed code can be tested more easily by replacing specific classes with mocks. [...] Sebastian then pushed the code as part of a new test_helpers extension with some documentation to github and I fixed some bugs in it. The aim of the extension is to collect functionality which might be beneficial for phpUnit and other test scenarios but which should never reach a production environment.
He includes some sample code to show it in action - defining the mock class, using the set_new_overload function to define it as what should be called when the "new" operator is used and a dump of the result.
voice your opinion now!
overload new operator mock unittest
Federico Cargnelutti's Blog: Testing Zend Framework Action Controllers With Mocks
by Chris Cornutt November 02, 2009 @ 07:58:44
In this new post to his blog today Federico Cargnelutti shows you how to use mock objects to unit test controllers in your Zend Framework application.
In this post I'll demonstrate a unit test technique for testing Zend Framework Action Controllers using Mock Objects. Unit testing controllers independently has a number of advantages: you can develop controllers test-first (TDD), develop and test all of your controller code before developing any of the view scripts and helps you quickly identify problems in the controller, rather than problems in one of the combination of Model, View and Controller.
He sets up a sample user controller and a test case to go along with it. Drop in a test for the user controller class that uses a "getMock" method to define a mock controller object for the "render" method. He also points out a few issues with this sort of testing in the Zend Framework - the return value of the Zend_Test_PHPUnit_ControllerTestCase, issues throwing exceptions with the Front Controller and a problem with the dispatcher's storage of the Action Controller.
voice your opinion now!
action controller zendframework test mock object
Jani Hartikainen's Blog: Unit testing 4 Mock objects and testing code which uses the database
by Chris Cornutt June 29, 2009 @ 11:43:14
Jani Hartikainen has posted the fourth part of his unit testing series looking at using mock objects when testing database interfaces.
When testing a class which needs an instance of another class to work, you do not want to depend on the other class too much. This is where mock objects come in - a mock object is a "clone" of an object, which we can use to simplify our tests, by having the mock object perform assertions or by replacing some functionality of the mock with our custom functionality.
He introduces some of the basics of mocking objects and how to create mock objects with PHPUnit. He takes it up to the next level with a mock database example based on grabbing event details to return "fake" results from a sample dataset.
voice your opinion now!
database unittest object mock
Content With Style: Unit testing web service based models in Zend Framework
by Chris Cornutt April 29, 2009 @ 08:44:44
The Content with Style blog has continued their series looking at unit testing with the Zend Framework (see this previous post) with this look at testing services based models.
However, unit testing models that talk to web services presents us with a different set of problem. Usually our application runs requests against something that is not in our control. Unless the service provider gives us some kind of test mode, we're operating with dynamic live data which shouldn't be used for testing, since it's harder to test in the first place, but also could be harmful to be manipulated.
They present two method you can use to test the models: creating mock objects to handle and return correctly formatted data and intercepting the HTTP request to either send it to a Zend_HTTP adapter or a different endpoint (service location).
voice your opinion now!
unittest webservice model zendframework mock object endpoint http
Benjamin Eberlei's Blog: Test your Legacy PHP Application with Function Mocks!
by Chris Cornutt March 31, 2009 @ 11:18:31
Benjamin Eberlei has a suggestion for testing your application without having to mess around with creating new resources just for testing - use mocks.
Much talking is going on about Unit testing, Mocks and TDD in the PHP world. For the most this discussions surround object-oriented PHP code, frameworks and applications. Yet I would assert that the reality for PHP developers (me included) is dealing with PHP 4, PHP 5 migrated, or non-object oriented legacy applications which are near to impossible to bring under test.
He includes a "proof of concept" for a replacement mysql_query function (as created inside of Runkit) that sets up a "mocker" object that returns a "hello world" message when the mysql_query function is called.
voice your opinion now!
mock function runkit proofofconcept mysqlquery resource
Padraic Brady's Blog: Mocks, Stubs, And SimpleTest Wins
by Chris Cornutt November 12, 2007 @ 08:49:00
In a new post today, Padraic Brady talks about some of his experience with unit testing in PHP - specifically with two of the more popular testing applications - SimpleTest and PHPUnit.
The word is that SimpleTest is moving towards PHP5 in the near future which is great news for all Mockists in PHP. When I moved to PHP, SimpleTest became the main ingredient in many a coding session up to 2 in the morning but once PHP5 gained traction and I was seduced into leaving PHP4 behind I found myself relying more heavily on PHPUnit. Not that SimpleTest is anti-PHP5 in any way (only some small things and obviously E_STRICT giving it a heart attack), but more projects I didn't control leaned heavily towards PHPUnit once PHP5 took off.
He goes on to talk about some of the differences between the two pieces of software (including Mock Object support and Stubs) and his personal feelings on how each of them works in his development experience. His interest has leaned more towards needing the Mock objects, though, so he favors SimpleTest for doing just what he needs.
voice your opinion now!
simpletest phpunit unittest mock stub object simpletest phpunit unittest mock stub object
|
Community Events
Don't see your event here? Let us know!
|