Jan 19 2011

Using Zend_Form_Decorators to compose a form as table rows

Ahh Zend form decorators, they certainly have a reputation of being quite difficult to pick up. I suffered similar problems but persevered to get the table layout I wanted.

$form->setElementDecorators(array(
    'ViewHelper',
    array('Description', array('tag' => 'span')),
    array('Errors'),
    array('HtmlTag', array('tag' => 'td')),
    array('Label', array('tag' => 'th', 'requiredSuffix' => ' *')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
));

The above code will result in the following (albeit not quite as neatly):

<tr>
    <th>Label *</th>
    <td>
        <input type="text" /><span class="hint">Description</span>
        <ul class="errors"><li>Error</li></ul>
    </td>
</tr>

For reference example was written with Zend Framework 1.11.2.

Jan 12 2011

Exporting a git tag in a Phing target and subsequently processing the files

Composing releases with git archive is very useful, especially when making use of the .gitattributes file to select what is archived.

One way to make use of this command in Phing, is to do the following:

<target name="build" depends="prepare">
    <exec command="git archive ${git_tag} | tar -x -C ./_build" />
</target>

This allows processing of the archived files. For example, the target could be expanded to strip PHP comments:

<target name="build" depends="prepare">
    <exec command="git archive ${git_tag} | tar -x -C ./_build" />

    <reflexive>
        <fileset dir="./_build">
            <include pattern="**/*.php" />
        </fileset>
        <filterchain>
            <stripphpcomments />
        </filterchain>
    </reflexive>
</target>
Jan 09 2011

PHPUnit code coverage output in Windows including PHPUnit classes

Having just to got to the point where I was happy with my distributed project builds on Windows and Linux, I discovered my code coverage reports generated by PHPUnit were different between the two.

On the Linux machine, just the classes I expected were included in the report. On Windows however, it included some of the PHPUnit classes.

Turns out I had to create a phpunit.xml configuration file and include a whitelist of files.

For example:

<?xml version="1.0" encoding="UTF-8"?>
    <phpunit>
        <filter>
            <whitelist>
                <directory suffix=".php">./src</directory>
            </whitelist>
        </filter>
        <logging>
            <log type="junit" target="./build/logs/testsuites.xml"/>
            <log type="coverage-clover" target="./build/logs/coverage-clover.xml"/>
        </logging>
    </phpunit>

Info

I'm Ade Slade, a PHP web developer.