On the Xebee blog there’s a recent post looking at test-driven development with the Zend Framework and PHPUnit.
Over the past few days I was going through the Zend Framework reference docs and I found myself pleasantly surprised with all that the latest version of this web application framework provides. My first thought was to just acknowledge the speed in which PHP as a technology has been maturing. Out of the many new features, what stood out for me was the ease with which Zend Framework and PHPUnit complement and work with each other.
They show how they use PHPUnit, Zend_Test and Selenium to create database and acceptance/functional tests.
On his blog Matthew Turland is sharing his first time experience working with Zend_Test.
I worked on a project recently where we used Zend Framework. As part of that project, I was tasked with writing unit tests. So, I went to the “tests” directory generated for me by the zf CLI utility to get started. What I found there was three files. […] They were all completely empty, which didn’t really provide much in the way of guidance on how to get started. The Zend_Test documentation is good, but was a bit lacking in that area as well; it really only covers how Zend_Test extends the capabilities of PHPUnit.
Mathew walks you through entire process of preparing simple testing environment for Zend_Test, from explaining auto-generated “tests” folder content, through configuration and bootstrapping, to writing and running controller test, including database support and fixtures.
There has been lots post published about unit testing in Zend Framework recently. Most of them show how to setup simple testing environment and write simple test. In his recent post Giorgi Sironi shows how not to test Zend Framework action controllers.
Yesterday on twitter a discussion started about how to properly design Zend Framework action controllers to allow simplicity of testing, specifically how to inject collaborators in controllers and to avoid breaking the law of Demeter.
Presented real life example seems to be simple and typical. Giorgio explains what is wrong about it and what kind of obstacles from unit testing point of view it creates. The post is not only about how no to test controllers but also about what controllers should and should not do.
Update
Giorgio’s post has its continuation, where he explains why we can drop unit testing controllers and what controllers really do.
Update 2
Giorgio published another follow up to his, as we see controversial, post.
Michelangelo van Dam gave recently a presentation about testing Zend Framework applications. His presentation triggered discussion and lots of questions about setting up testing environment for Zend Framework. Because of that he decided to post tutorial about creating the environment, writing simple test, running it and generating some metrics.
We start off by setting our environment best fitted for our unit testing. I use a virtual linux system for this, using VMWare, but with some extra background research these global settings can be applied for your own (test) environment as well.
This is well written introductory tutorial about testing action controllers. It lets you start testing action controllers in 5 minutes.
A year (and a bit) after releasing PHPUNit 3.3.0 Sebastian Bergmann has released first stable version of new PHPUnit 3.4 line. Among lots of improvements and fixes, about which you can read in changlog, new version introduces support for test dependencies, fixture reuse and running tests in separated processes. Sebastian reveals also what new features PHPUnit 3.5 will have:
Work on PHPUnit 3.5 has already started: the php-code-coverage project on GitHub is home to a refactoring of PHPUnit’s code coverage functionality that will be one of the “hallmark features” of PHPUnit 3.5. It will also make PHPUnit’s code coverage functionality available outside the scope of PHPUnit.
PHPUnit is being used by Zend Framework team to write and run tests of the framework itself. It is also base library for Zend_Test component (Zend_Test_PHPUnit to be exact).