Testing Zend Framework can be very tricky. The team tries to make framework based applications as much testable as possible, but there are still parts of Zend Framework’s written the way it’s hard to test code based on it. Recently Georgio Sironi was writing about testing view helpers. Today Federico Cargnelutti writes about testing action controllers using mocks.
Unit testing controllers independently has a number of advantages:
- You can develop controllers test-first (TDD).
- It allows you to develop and test all of your controller code before developing any of the view scripts.
- It helps you quickly identify problems in the controller, rather than problems in one of the combination of Model, View and Controller.
What is very interesting about Federico’s post, is that he not only shows example test, but also points reader to some framework’s known issues preventing developers to test particular things. Naturally solution for mention issues is also provided.
Scalability problems are kind of problems many developers and entrepreneurs would like to have. I your already dealing with such problems, you had to notice important feature missing in Zend_Db – support of database replication.
Database replication is an option that allows the content of one database to be replicated to another database or databases, providing a mechanism to scale out the database. Scaling out the database allows more activities to be processed and more users to access the database by running multiple copies of the databases on different machines.
In a recent post on his blog Federico Cargnuletti presents his implementation of Zend_Db replication adapter. It supports single-master and multi-master architectures, as well as connection status caching. Read his post and code before implementing your own replication adapter – you might have it already done.
Zend Framework’s MVC pattern implementation is often criticized for models not being model as definition says. Zend Framework Team even does not pretend that framework has models, although suggests using Zend_Db component classes as simple and dirty replacement. It does not mean that community can’t do anything about it.
In his latest post Federico Cargnelutti shows how DAO, DAL and Data Mappers can be implemented in Zend Framework. He explains purpose of DAO, DAL and Data Mappers, proposes directory structure for it shows example implementation of all the classes.
His approach is very interesting and ready to use. Who knows, maybe it will be a sparkle for new component proposal, the model.