Testing: March 2008 Archives

While it's absolutly correct that direct access to private properties is strictly forbidden in PHP, it's quite disturbing that even reflection cannot do it when you're writing Unit Tests. Sometimes you just want to test whether a private property contains the correct data. With the normal visibility rules you cannot access those from your Unit Tests.

Luckily, as I just read at Tobias Schlitt's Blog, Derick Rethans committed a patch to the PHP 5.3 repository, which allows you to get things done quite easily. You still need to explicitly state that you want to access the value of a protected/private property through reflection by the new method setAccessible(). It's a good thing to avoid people doing stupid things accidentally, but you finally get the access to it.

PHP 5.3 you'll be able to access private properties like this:

But until we'll see a stable PHP 5.3, there we're many working "hacks", which worked for some versions of PHP 5.x - the most current one would be this:

This should get you up and running for PHP 5.2.5 ("older hacks" won't work).

So how could you use it?

I hope those lines of code will help you until PHP 5.3 arrives, as it helps our developers.

Update

As Sebastian points out in his comment to this post, PHPUnit has had support for testing private and protected attributes for quite a while. It can be used via:

I should be reading the documentation much more thoroughly next time (even though I must admit, that none of our developers has known this method, too).

Sometimes it seems writing tests with a good coverage is easier to be done than keeping your folks doing them, actually.

Truth be told, during the last four months our software developers had a rather easy life when it came to writing tests. We've been engineering our two platforms (with about 12 billion PI in January 2008) studiVZ and schuelerVZ from the ground up. We've also created our third platform, meinVZ.

With really tight timelines it's extremely hard to do extensive testing. Nonetheless we've been really succesful in (re)launching the platforms. But now it's time time to remind our engineers that we will extent our testing efforts again.

testing-motivation-01.jpgA few days ago Sebstian Bergmann contacted me via ICQ about a now very popular photo over at Mayflower GmbH.

After I saw this photo, I thought: "what a perfect match"! It's just a funny way to motivate our engineers even more. Just a few moments later the first copy was printed and attached to our QA walls.

Just a few days later Sebastian released another two motivating pictures that made their way onto our walls.

Sebastian: Thank you very much!

testing-motivation-02.jpgtesting-motivation-03.jpg

August 2008: Monthly Archives

Recent Activity

Sunday

  • I tweeted, "Let's continue working on the iPhone app ... but WTF does Apple keep the NDA?"
  • I tweeted, "Let's get some sleep - developing an iPhone application has been a lot of fun today ..."
Friday

  • I tweeted, "I'm off to the weekend - thanks god! And it's it's just another 11 days until the next holidays to southern spain ..."

More ...

Programming Blogs - BlogCatalog Blog Directory
Creative Commons License
This weblog is licensed under a Creative Commons License. blogoscoop

About this Archive

This page is a archive of entries in the Testing category from March 2008.

Testing: August 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.