Sommaire |
[modifier] Development IDE
We use Eclipse with the module PHPEclipse
[modifier] Installation
[modifier] Eclipse 3.1
As you can read in Plog4u web site, the debug mode of PHPEclipse 1.1.8 don't work with Eclipse 3.2. So we have to install Eclipse 3.1.
- Download Eclipse 3.1
- Unzip the file eclipse-SDK-3.1-win32.zip in the directory where you want install Eclipse
[modifier] PHPEclipse
- Open the Eclipse menu Help->Software Updates->Find/Install
- Choose "search for new features to install".
- And "New Remote Site"
- Choose en name (PHPEclipse), and the URL: http://phpeclipse.sourceforge.net/update/cvs
- "Finish".
- select "phpeclipse" and Next
- Follow the last instruction
[modifier] DBG Debugger
- Download DBG 2.15.5 dbg modules
- Copy php_dbg.dll (win32) or dbg.so (linux) in the ext directory of the PHP installation
- Add extension=php_dbg.dll (win32) or extension=dbg.so (linux) in your php.ini
- Activate the debugger: modify your php.ini file :
[debugger]
debugger.enabled = true
debugger.profiler_enabled = true
debugger.JIT_host = clienthost
debugger.JIT_port = 7869, 10000/16
clienthost is a keyword for DBG. If you use it, DBG will detect the IP adress of the client
Control your configuration using phpinfo()
[modifier] How to use it
It's not really easy to use it. It's really slow. If you try to debug something like MediaWiki Extension, it's an horror ... but sometimes it's useful ...but in much of case I prefer using small Unit Tests.
now you have to create a new debug configuration in PHP DBG Script (after click on "Debug As" in Eclipse). In the main form :
- The project
- The file to debug
In the Environnement tab
- Interpreter (php.exe)
- select Remote Debug
- indicate Remote Source Path
and let's go ...
To activate the debugger, after starting the debug in Eclipse, you have to add the parameter DBGSESSID=1@localhost:10001 to the URL you want debug. (10001 is the port of listening of the debugger, visible from the debug view Debug of Eclipse)
More information about DBGSESSID
If you want that the debugger stops on a breakpoint, the file containing the breakpoint must be open
[modifier] Unit Testing
--Martin Fowler
The phpunit documentation
[modifier] Installation
You have to use pear to install phpunit, see the pear manual for how to install it. For phpunit, you have to declare the channel if it is not already done :
pear channel-discover pear.phpunit.de
And the result
Adding Channel "pear.phpunit.de" succeeded Discovery of channel "pear.phpunit.de" succeeded
And now you can start the installation :
pear install phpunit/PHPUnit
[modifier] How to use it
As said the author (Sebastian Bergmann) in is book
But the book is really useful
Some tips :
- One file per class, it is simpler… especially if it has the same name than the class. In other case --skeleton doesn't work fine
- Be careful at the naming rules of PEAR used to find files, but your free to respect it or not
- How to create the skeleton of a class test:
phpunit --skeleton Le_nom_de_la_classe
[modifier] Test covering measure with XDebug
Using together with PHPUnit, Xdebug gives really useful informations to make sure that all the code is correctly covered. With PHP more than in any other compiled language, measuring the unit tests cover of code is an invaluable pledge of reliability.
That avoids ending up falling one day on a stupid case which crash your site because of a non-existent function or of one $ front a variable forgotten.
[modifier] Installation
Simple, téléchargez le fichier correspondant à votre version de PHP sur xdebug.org (à droite), puis copiez le dans votre répertoire d'extension. Simple, download the file corresponding to your version of PHP on xdebug.org (on the right), then copy it in your extension directory.
Then, in the php.ini of your installation directory (shell) and in that of Windows (module apache) add after the extensions the line (by adapting the path to your configuration):zend_extension_ts= F:\PHP\ext\php _xdebug-2.0.0rc3-5.2.1.dll
[modifier] How to use it
To produce the coverage rapport of the MainPackage class:
phpunit --report ./report MainPackage
