Development

This very first article on developing for TYPO3 describes how configuring your environment. Following sections show the toolbox I use: PHPUnit, Xdebug, Zend Debugger and PhpStorm.

PHPUnit

PHPUnit is a framework to be used for Unit Tests in PHP.

Under TYPO3, one may install the extension  phpunit that provides a backend module allowing execution of the tests and presenting test reports as shown on following screenshot.

Installation

In TYPO3 backend, install extension PEAR Manager ( pear). After the initial configuration, add a new channel for PEAR (channel discovery) in order to get the latest and non deprecated version of PHPUnit. Canal to use is

pear.phpunit.de

Then in section Package Management, install phpunit/PHPUnit.

We are now able to use the PEAR version of PHPUnit by ticking the checkbox usepear in the setup form of the extension phpunit, in Extension Manager.

Crash

I was unable to use PHPUnit because Apache kept crashing. I finally found that I had to deactivate option alwaysSimulateFrontendEnvironment in this extension’s setup form and this, although I first tried to extend the  memory_limit in php.ini up to 3 GB!

However, there is no need to deactivate extension  phpmyadmin anymore if you use it.

Xdebug

Xdebug is a PHP extension that helps you debugging your script by providing a lot of valuable debug information.

Another feature to be pointed out is that if you use the TDD methodology ( Test-Driven Development), it will be able to show you code coverage reports.

Here is how you may install this library on Mac OS X 10.5 (Leopard). The version I used (2.0.3) is the latest stable release from April 2008. However, you should use the latest version available from the official website  http://www.xdebug.org.

$ curl www.xdebug.org/files/xdebug-2.0.3.tgz -O
$ tar xzf xdebug-2.0.3.tgz
$ cd xdebug-2.0.3
$ phpize
$ CFLAGS='-arch x86_64' ./configure --enable-xdebug
$ make

Let’s copy the compiled binary. On my computer PHP libraries are located in /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613:

$ sudo cp modules/xdebug.so /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/

You may retrieve the directory for your PHP install using:

# php -i | grep extension_dir

Now we should load this library with PHP. Let’s create file /usr/local/php5/php.d/50-extension-xdebug.ini:

zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so

Check that Xdebug is now loaded as a Zend extension:

$ php -m
[PHP Modules]


[Zend Modules]
Xdebug

After restarting Apache, we may issue a phpinfo(); to make sure Xdebug is available too.

A really useful Firefox extension:  Easy Xdebug.

Zend Debugger

Zend Debugger is an extension that may be run separately from their different Zend Servers, using your existing Apache + PHP system. It is freely available from  http://www.zend.com/en/products/studio/downloads.

Instruction to install it are pretty straightforward:

  1. Extract the Zend Debugger package
  2. Locate the ZendDebugger.so file in the directory which corresponds to your version of PHP (typically 5_2_x_comp or 5_3_x_comp)
  3. Copy the extension to the PHP extension directory:. On my computer (using MacPorts) PHP libraries are located in /opt/local/lib/php/extensions/no-debug-non-zts-20060626:
    $ php -i | grep extension_dir
    extension_dir => /opt/local/lib/php/extensions/no-debug-non-zts-20060626/
    $ sudo cp ZendDebugger.so $(php -i | grep extension_dir | sed 's/^.* => \(.*\)/\1/')
  4. Create file /opt/local/php5/php.d/50-extension-zenddebugger.ini or /opt/local/var/db/php5/zenddebugger.ini if using MacPorts:
    zend_extension=/opt/local/lib/php/extensions/no-debug-non-zts-20060626/ZendDebugger.so

    zend_debugger.allow_hosts=127.0.0.1
    zend_debugger.expose_remotely=always
  5. Copy package file dummy.php to your document root directory (in our case this is the root of our TYPO3 website, next to index.php or directory typo3conf)
  6. Restart your webserver

You should be able to debug your TYPO3 website using the Zend browser toolbar that is installed with Zend Studio:

Further Reading

Step-by-step debug session

  • Eclipse + PDT + XDebug [ Video]
Flattr