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:
Testing Traits
January 12, 2011 @ 14:10:28

In some of the work he was doing Sebastian Bergmann came across an instance where he needed to both use a trait in his application and try to figure out how to test it with PHPUnit.

To make sure that I did not break anything, I ran the test suite for the BankAccount sample application. The tests for classes that previously extended HashMap (Response, for instance) still passed. Of course, the tests for HashMap were now broken because trait cannot be instantiated. Suddenly I had to think about making traits testable.

He's worked up a way to test them by creating a test just for the trait and using the new "getObjectForTrait" method to instantiate an object. It returns a mocked up version of the object that can be fully interacted with. You'll need to get PHPUnit 3.6 to be able to use this feature, though.

2 comments voice your opinion now!
phpunit unittest traits example getobjectfortrait


blog comments powered by Disqus

Similar Posts

Volker Dusch's Blog: Setting up Hudson for PHP Projects in 15 minutes

Matthias Noback: A better PHP testing experience Part I: Moving away from assertion-centric testing

Marcelo Gornstein's Blog: Unit test your PHP IVR applications with PAGI

PHPBuilder.com: Using PHP for the Creation of SVG Images

Adam Bard: The Same App 4 Times: PHP vs Python vs Ruby vs Clojure


Community Events





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


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

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