Software for the web

Hello and welcome to AVNet Labs, my portfolio and blog. I build accessible and standards-compliant websites and web applications that account for speed, accessibility and usability while adhering to web standards.

Latest journal entries

TDD with Zend Framework – wrapping up the controller

January 4th, 2010
  • Part 1 - Getting Started
  • Part 2 - Testing Controllers
  • Part 3 - Mocks and Stubs
  • Part 4 - Wrapping up the controller
    • The last part of this series dealt with mocking and stubbing the controller action dependencies to get isolated unit tests. In this section we'll round up the controller tests.

      • There is some repetition in the controller test and it'd be nice to clean that up.
      • Our subscribe action redirects to a thank you page. That doesn't exist yet.
      • Our subscribe action expects a POST. We need to verify the behaviour if it receives a GET instead.

      When we left off, we had the following controller class: [php] <?php class IndexController extends Zend_Controller_Action { public function indexAction() { ...

TDD with Zend Framework – mocks and stubs

January 3rd, 2010
  • Part 1 - Getting Started
  • Part 2 - Testing Controllers
  • Part 3 - Mocks and Stubs
  • Part 4 - Wrapping up the controller
    • In the last part we tested for the form elements on the home page to meet the first of our requirements. In this part we'll take on a few more requirements starting with the requirement that the form should be redisplayed when I submit invalid details.
      For the details to be invalid it means we have validated the data and it failed validation. However our validation code is not done yet but we still need to ensure the controller and view do what we require when the details are invalid.

      Zend_Form straddles both the view and model ...

Zend Framework 1.8 Web Application Development – book review

November 17th, 2009

I've just finished going through Zend Framework 1.8 Web Application Development, a new book by Keith Pope. Published by Packt Publishing this book which somehow manages to cater to the ZF beginner as well as the veteran developers is a must-read for anyone doing Zend Framework development.

First impressions are "this guy sure knows his stuff".
Subsequent impressions are "how the &^%$ did this guy know all this stuff?".
The first three chapters are aimed at ZF newbies but even at that I still found a lot of nuggets I had managed to overlook even after working with the Zend Framework for almost 2 years. The first two chapters kick off with a run-through of a Zend ...

TDD with Zend Framework – testing controllers

November 15th, 2009
  • Part 1 - Getting Started
  • Part 2 - Testing Controllers
  • Part 3 - Mocks and Stubs
  • Part 4 - Wrapping up the controller
    • In the first part of this series we set up our Zend Framework application and specified our requirements. In this part we'll tackle the first requirement - as a user, I want to visit the home page and see a form where I can enter my full name and email address.

      As a first test, I'll make sure I can 'GET' the home page. I do this by testing the Index controller's Index action. I have shown my preferred test directory structure below but here again the Zend Framework has no set structure. [bash] tests |--application ...

TDD with Zend Framework

November 2nd, 2009
  • Part 1 - Getting Started
  • Part 2 - Testing Controllers
  • Part 3 - Mocks and Stubs
  • Part 4 - Wrapping up the controller
    • Jani Hartikainen has an interesting unit testing series on his blog where he introduces and expands on unit testing php code with phpunit. It's a really good read and it pushed me to add his feed to my reader so I could stop going to the site daily to check for updates.

      However, as useful as the series is, it doesn't provide answers to Zend Framework specific testing issues (and considering all the ZF-specific posts on his site, that's quite surprising). It is also aimed at beginner programmers. Most of the programmers I work with don't need ...

Bullshit of the day

August 25th, 2009

From a Virgin Media call center agent before trying to get me to upgrade my package at a 'discount': "Your name has been added to the list of our valued customers."

To me this seems to imply

  • I hadn't been valued all the time I'd been with them.
  • They still have customers who pay them money every month who aren't valued.
I'm sure she didn't like my answer. I expected more from Virgin.

Restful Controllers with Zend Framework

August 20th, 2009

I just read Bradley Holt's post on using HTML 5 forms with REST and HTTP methods and he mentioned the REST router in the recently released version 1.9 of the Zend Framework. The good news is we don't have to wait for mainstream support for HTML 5.
Zend Framework REST controller supports PUT and DELETE HTTP methods right now through overloading the POST method (ok, it's a bit of hack - but it's worked in Rails for ages). Although the ZF 1.9 announcement mentions using Zend_Rest_Route for public APIs, building any application (or parts of it) restfully has a couple of advantages:

Zend_Db_Table update in ZF1.9

July 26th, 2009

I usually have a bunch of empty Db_Table classes in my Zend Framework apps which just exist to define table names and do the inherited CRUD stuff.

However, with the just released version 1.9 of the framework (currently in beta), I don't need to do this anymore. Zend_Db_Table is now a concrete implementation that accepts a table name as a parameter and can do all the CRUD stuff without needing a class to be defined.

Obviously, if custom code needs to be added to the Db_Table instance a class needs to be created but this will still go a long way towards cleaning up my models folder.

As an example:

  • The old way [php] class Books extends Zend_Db_Table_Abstract { protected $_name = 'books'; } // and in the controller ...