Zend Framework 1 is not dead; ensure you upgrade!

18th December 2012

I'm delighted to announce that Zend Framework 1.12.1 has been released! This release fixes 50 issues which is a great result. I'd like to thank everyone who submitted a patch to ZF1 and to Matthew Weier O'Phinney, Frank Brückner and Mike Willibanks in particular for their work on this release.

There's a few important things to note:

  • There's a security fix in 1.12.1. Please read ZF2012-05 if you use Zend_Feed_Rss or Zend_Feed_Atom.
  • The minimum PHP version for ZF 1.12.0 and ZF 1.11.12 is 5.2.11 due to security fixes for ZF2012-03.
  • Zend_Markup_Parser_Textile has been removed from 1.12.1 as it was significantly broken.

As I said in the title of this post, ZF1 isn't dead: we have committed to supporting it until at least 2014 so we will have more releases as required either due to security issues found or because we've accumulated enough bug fixes in the codebase. With that in mind, please continue to raise issues on the issue tracker if you find any issues in 1.12.1. We'd also appreciate your patches if you can fix any of the issues! I'm on IRC if you want any help (Akrabat in the #zftalk.dev channel on Freenode).

ZF1.12 is released

28th August 2012

I'm extremely happy to note that Zend Framework 1.12 has been released and is available here.

The key changes are:

  • ZF2's StandardAutoloader and ClassMapAutoloader have been back ported to `Zend_Loader`.
  • ZF2's EventManager has been back ported to `Zend_EventManager`
  • New `Zend_Http_UserAgent_Features_Adapter_Browscap` component
  • New `Zend_Mobile_Push` component, contributed by Mike Willibanks
  • New `Zend_Gdata_Analytics` component, contributed by Daniel hartmann
  • `Zend_Http_UserAgent_Features_Adapter_Wurfl` has been removed due to WURFL licensing changes
  • Many many bug fixes! See the changelog

Getting ZF1.12 out of the door took longer than I imagined when I took on the release management role. I'd particularly like to thank Matthew Weier O'Phinney, Enrico Zimuel, Ralph Schindler, Adam Lundrigan, Frank Brückner and Martin Hujer for their work on the code. I'd also like thank the many people who ran the ZF1 unit test suite for us too.

You should upgrade if you're using 1.10 or 1.11 as it should be hassle free!

Vagrant in Zend Framework 1

9th May 2012

I recently added support for vagrant to the Zend Framework codebase to enable easier testing. I was motivated by some work the joind.in folks have done to get a working development environment for joind.in development using Vagrant.

Vagrant is a fantastic tool that enables you to manage and run virtual machines from the command line, including automatic provisioning of them using puppet or chef. The really cool thing about it however from my point of view is that vagrant automatically sets up the VM with a folder called /vagrant that holds the code on your local hard drive from where you started the VM. This means that you can continue to edit your code in your local editor/IDE and test it within the VM easily.

I highly recommend checking it out.

ZF1's Vagrant set up

The Vagrant set up for ZF1 is designed for testing ZF1 against multiple PHP versions. As such it sets up a simple Ubuntu VM with the required toolchain for compiling PHP and provides a script called php-build.sh which will download and build any PHP 5.2, 5.3 or 5.4 version that you are interested in. I based this script on information in Derick Rethans' excellent Multiple PHP versions set-up article.

One thing that I discovered was that by default, the VM cannot create symlinks in /vagrant. The way to solve this is to add the following to the Vagrantfile:

  config.vm.customize [
    "setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"
  ]

I chose to use puppet to install the required packages and created a simple default.pp configuration. I'm sure this isn't optimal, but it works :)

Running ZF1 unit tests

The process to set up ZF1 to run unit tests in a VM using PHPUnit 3.4, follow these steps:

1. Install requirements for running the VM:

2. Checkout the ZF1 repository:

    $ svn checkout http://framework.zend.com/svn/framework/standard/trunk zf1-dev
    $ cd zf1-dev

3. Start the process by running Vagrant.

    $ vagrant up

This will take a long while as it has to download a VM image and then provision it. Once it has finished, it will exit and leave you back at the command prompt.

4. SSH into the VM

    $ vagrant ssh

Vagrant sets up key-less ssh connections to the VM that "just works" :)

5. Build a version of PHP.

    $ php-build.sh 5.3.11

This also takes a while as it compiles PHP for you! It also installs PHPUnit 3.4 as that's the version we need to unit test ZF1.

Each version of PHP that you compile is stored in /usr/local/php/{version number}. You can compile any version; I have 5.2.4, 5.2.12, 5.3.3 and 5.3.11 installed at the moment…

6. Select PHP to use:

   $ pe 5.3.11

pe is a handy shell function that Derick wrote that changes your PHP environment to whichever version your specify.

7. Run tests

   $ cd /vagrant/tests
   $ php runtests.php

Alternatively, you can run each component's tests individually:

   $ phpunit --stderr -d memory_limit=-1 Zend/Acl/AclTest.php
   $ phpunit --stderr -d memory_limit=-1 Zend/Amf/AllTests.php
   (etc...)

Obviously, you repeat steps 5 through 7 for each version of PHP you want to test on.

To stop your Vagrant VM, exit the SSH shell and type `vagrant halt` or `vagrant suspend`. For more details on controlling your Vagrant VM, I recommend Lorna's article

Running unit tests on Zend Framework 1 is now considerably easier!

Unit testing Zend Framework 1

30th April 2012

As part of our release process for Zend Framework 1.12, I've been working through the unit tests and running them on PHP 5.2.4 as it seems that recent changes weren't being tested with that version. This isn't totally surprising as Open Source contributors are, almost by definition, interested in new things and so are much more likely to be running PHP 5.4 rather than 5.2! This is, of course, a compelling reason for using continuous integration and I'm quite excited with Travis-CI and we are using it with ZF2.

Installing PHPUnit 3.4

The first challenge that I encountered was that ZF1's unit test are not compatible with PHPUnit 3.6. As there are over 14,000 ZF1 unit tests which have been written since 2006, there hasn't been much enthusiasm for rewriting them to be PHPUnit 3.6 compatible. (However, if someone wants to volunteer, please contact me!)

As I have PHPUnit 3.6 installed for testing other projects, I needed to install PHPUnit 3.4 side-by-side with version 3.6 This turns out to be relatively easy and has been documented by Christer Edvartsen in his article Running Multiple Versions of PHPUnit.

I ran into one problem with his instructions though and needed this code to be added to the top of phpunit:

// For OS X 10.7
set_include_path(implode(PATH_SEPARATOR, array(
    __DIR__ . '/../share/php',
    '/usr/share/php',
    get_include_path()
)));
 
// Or for OS X 10.8
set_include_path(implode(PATH_SEPARATOR, array(
    __DIR__ . '/../lib/php/pear',
    '/usr/lib/php/pear',
    get_include_path()
)));

Having done this though, PHPUnit 3.4 works correctly and we can run ZF1 unit tests.

Running the ZF1 unit tests

To run ZF1's unit tests, you first need to check out the code from the Subversion repository.

svn co http://framework.zend.com/svn/framework/standard/trunk/

Due to the number of tests and the memory that they take up, you should run tests for each component individually.

The command to use is:

phpunit34 --stderr -d memory_limit=-1 Zend/{Component}/AllTests.php

Note:

  • --stderr pipes PHPUnit's output to stderr which means that any tests that rely on header() will work. (i,e. don't test Zend_Session without it!)
  • -d memory_limit=-1 will turn off PHP's memory_limit setting. The ZF1 unit tests use a lot of memory, so this is easiest.
  • The tests rely on being set up correctly. This is done using AllTests.php so don't forget this. Tests will fail if you forget!

All that needs to happen now is that any failing tests are fixed!

One-to-many joins with Zend_Db_Table_Select

8th February 2012

Let's say that you want to set up a one-to-many relationship between two tables: Artists and Albums because you've refactored my ZF1 tutorial.

Let's assume that an artist has many albums. These are the basic table definitions:

artists table: id, artist
albums table: id, artist_id, title

When you list the albums, you obviously want to see the artist name rather than the id, so clearly you use a join!

Assuming you're using Zend_Db_Table, the easiest way is to turn off the integrity check and do a join in a mapper or table method.

Something like this:


class AlbumTable extends Zend_Db_Table_Abstract
{
protected $_name = 'album';

public function fetchAllWithArtistName($order = array('title ASC'))
{
$select = $this->select();
$select->setIntegrityCheck(false);
$select->from($this->_name);

$select->joinLeft('artist', 'album.artist_id = artist.id',
array('artist_name' => 'name'));
$select->order($order);

$rows = $this->fetchAll($select);
return $rows;
}

}

The row set returned will have all the columns from the albums table and one additional column called artist_name which is an alias of the name column from the artists table.