<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Pims Labs &#187; Intégration Continue</title>
	<atom:link href="http://labs.pimsworld.org/category/qualite/integration-continue/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.pimsworld.org</link>
	<description>Les labs de Pims World</description>
	<pubDate>Thu, 28 May 2009 08:15:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Phing automatise les opérations répétitives des développements PHP</title>
		<link>http://labs.pimsworld.org/2009/01/phing-automatise-les-operations-repetitives-des-developpements-php/</link>
		<comments>http://labs.pimsworld.org/2009/01/phing-automatise-les-operations-repetitives-des-developpements-php/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 11:09:18 +0000</pubDate>
		<dc:creator>Stéphane Roucheray</dc:creator>
		
		<category><![CDATA[Intégration Continue]]></category>

		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tutoriels]]></category>

		<category><![CDATA[automatisation]]></category>

		<category><![CDATA[ligne de commande]]></category>

		<category><![CDATA[svn]]></category>

		<category><![CDATA[tests unitaires]]></category>

		<category><![CDATA[Ubuntu]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://labs.pimsworld.org/?p=74</guid>
		<description><![CDATA[Phing est un outil Open Source d'automatisation des tâches répétitives pour les projets de développement PHP. Ce tutoriel rapide sur l'utilisation et l'installation de Phing vous permettra de créer rapidement vos premières tâches avec Phing. ]]></description>
			<content:encoded><![CDATA[<p>L&#8217;automatisation des opérations répétitives dans un projet de développement peut être résolue de multiples manières allant du simple script lancé à la main au système d&#8217;intégration continue.</p>
<p>La plupart des langages ont standardisé leurs outils, <a href="http://fr.wikipedia.org/wiki/Make">make</a> pour C, <a href="http://fr.wikipedia.org/wiki/Apache_Ant">Ant</a> pour Java&#8230; PHP bénéficie lui aussi d&#8217;un tel outil : <a href="http://phing.info">Phing</a>.</p>
<p>Phing est un projet Open Source très inspiré de Ant. Le concept est assez simple. Un fichier XML décrit une série d&#8217;actions possibles pouvant ou non être dépendantes les unes des autres et une ligne de commande permet de déclencher ces actions.</p>
<h2>Utilisation de Phing</h2>
<p>Un exemple rapide. Nous voulons vérifier que la syntaxe des fichiers PHP de notre projet est bien respectée, qu&#8217;aucune erreur ne s&#8217;y est glissée, le fichier XML ressemble alors à ça :</p>
<p><strong>Fichier build.xml</strong></p>
<div class="codecolorer-container xml " style="overflow:auto;white-space:nowrap;width:540px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;project</span> <span class="re0">name</span>=<span class="st0">&quot;premier_projet&quot;</span> <span class="re0">default</span>=<span class="st0">&quot;lint&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">name</span>=<span class="st0">&quot;lint&quot;</span> <span class="re0">description</span>=<span class="st0">&quot;Vérifie la syntaxe PHP&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;phplint<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fileset</span> <span class="re0">dir</span>=<span class="st0">&quot;/home/mon_projet/src/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;include</span> <span class="re0">name</span>=<span class="st0">&quot;**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;exclude</span> <span class="re0">name</span>=<span class="st0">&quot;lib/Zend/**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fileset<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/phplint<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/project<span class="re2">&gt;</span></span></span></div></div>
<p>Enregistrez ce fichier avec le nom build.xml (le fichier par défaut utilisé par phing) dans le dossier build de votre projet, par exemple</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">/</span>home<span class="sy0">/</span>mon_projet<span class="sy0">/</span>build<span class="sy0">/</span></div></div>
<p>Ouvrez une console et lancez ensuite la commande phing depuis le dossier du fichier build.xml</p>
<p><strong>Commande</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw3">cd</span> <span class="sy0">/</span>home<span class="sy0">/</span>mon_projet<span class="sy0">/</span>build<span class="sy0">/</span><br />
phing</div></div>
<p>Le fichier build.xml est très explicite, cette commande va donc vérifier, pour tous les fichiers PHP de mon dossier source a l&#8217;exclusion de ceux de la bibliothèque Zend, que leur syntaxe est bien respectée.</p>
<p>Autre exemple, pour générer automatiquement la documentation de classes PHP.</p>
<p><strong>Fichier build.xml</strong></p>
<div class="codecolorer-container xml " style="overflow:auto;white-space:nowrap;width:540px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;project</span> <span class="re0">name</span>=<span class="st0">&quot;premier_projet&quot;</span> <span class="re0">default</span>=<span class="st0">&quot;doc&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">name</span>=<span class="st0">&quot;doc&quot;</span> <span class="re0">description</span>=<span class="st0">&quot;Génère la documentation&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;phpdoc</span> <span class="re0">title</span>=<span class="st0">&quot;API Documentation&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">destdir</span>=<span class="st0">&quot;/home/mon_projet/api&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">sourcecode</span>=<span class="st0">&quot;no&quot;</span> <span class="re0">output</span>=<span class="st0">&quot;HTML:Smarty:PHP&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fileset</span> <span class="re0">dir</span>=<span class="st0">&quot;/home/mon_projet/src/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;include</span> <span class="re0">name</span>=<span class="st0">&quot;**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;exclude</span> <span class="re0">name</span>=<span class="st0">&quot;lib/Zend/**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fileset<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/phpdoc<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/project<span class="re2">&gt;</span></span></span></div></div>
<p><strong>Commandes</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw3">cd</span> <span class="sy0">/</span>home<span class="sy0">/</span>mon_projet<span class="sy0">/</span>build<span class="sy0">/</span><br />
phing</div></div>
<p>Phing tout comme Ant gère la dépendance des tâches. Dans notre cas, si nous voulons générer la documentation après la vérification syntaxique. Il suffit de modifier notre fichier build.xml comme suit :</p>
<p><strong>Fichier build.xml</strong></p>
<div class="codecolorer-container xml " style="overflow:auto;white-space:nowrap;width:540px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;project</span> <span class="re0">name</span>=<span class="st0">&quot;premier_projet&quot;</span> <span class="re0">default</span>=<span class="st0">&quot;build&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">name</span>=<span class="st0">&quot;lint&quot;</span> <span class="re0">description</span>=<span class="st0">&quot;Vérifie la syntaxe PHP&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;phplint<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fileset</span> <span class="re0">dir</span>=<span class="st0">&quot;/home/mon_projet/src/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;include</span> <span class="re0">name</span>=<span class="st0">&quot;**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;exclude</span> <span class="re0">name</span>=<span class="st0">&quot;lib/Zend/**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fileset<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/phplint<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">name</span>=<span class="st0">&quot;doc&quot;</span> <span class="re0">description</span>=<span class="st0">&quot;Génère la documentation&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;phpdoc</span> <span class="re0">title</span>=<span class="st0">&quot;API Documentation&quot;</span> </span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">destdir</span>=<span class="st0">&quot;/home/mon_projet/api&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">sourcecode</span>=<span class="st0">&quot;no&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">output</span>=<span class="st0">&quot;HTML:Smarty:PHP&quot;</span><span class="re2">&gt;</span></span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fileset</span> <span class="re0">dir</span>=<span class="st0">&quot;/home/mon_projet/src/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;include</span> <span class="re0">name</span>=<span class="st0">&quot;**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;exclude</span> <span class="re0">name</span>=<span class="st0">&quot;lib/Zend/**/*.php&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fileset<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/phpdoc<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> </span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">name</span>=<span class="st0">&quot;build&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">depends</span>=<span class="st0">&quot;lint, doc&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">description</span>=<span class="st0">&quot;Syntaxe PHP et Documentation&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/project<span class="re2">&gt;</span></span></span></div></div>
<p><strong>Commande</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">phing</div></div>
<p>La commande <tt>phing</tt> va automatiquement séquencer les 2 tâches <tt>lint</tt> et <tt>doc</tt> car la tâche <tt>build</tt> dépend d&#8217;elles.<br />
Si nous voulons seulement générer la documentation il suffit de taper la commande suivante.</p>
<p><strong>Commande</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">phing doc</div></div>
<p>Phing est très puissant. Il permet de gérer des tâches conditionnelles, des tâches spécifiques PHP comme l&#8217;analyse de code par le compilateur Zend, le lancement de tests unitaires classiques ou avec <a href="http://labs.pimsworld.org/2008/12/installation-de-selenium-rc-sous-ubuntu">Selenium</a>. Il sait aussi piloter des tâches plus génériques comme l&#8217;update de dépôt SVN ou l&#8217;exécution de commandes externes. La liste longue et complète des tâches disponibles se trouve dans la documentation de <a href="http://phing.info/docs/guide/current/">Phing</a>.</p>
<h2>Installation de Phing</h2>
<p>Pour installer Phing, le plus simple est d&#8217;utiliser PEAR. Sous Ubuntu tapez les commandes suivantes en mode super utilisateur.</p>
<p><strong>Installation de PEAR, la bibliothèque d&#8217;extensions à PHP</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">apt-get</span> <span class="kw2">install</span> php-pear</div></div>
<p><strong>Installation de Phing</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:540px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">pear channel-discover pear.phing.info<br />
pear <span class="kw2">install</span> phing<span class="sy0">/</span>phing</div></div>
<h2>On en parle ailleurs&#8230;</h2>
<p>Un <a href="http://nsslive.net/2009/02/16/shell-scripts-no-more/">article en anglais de Nabeel Shahzad</a> décrit comment il s&#8217;est débarrassé des scripts grâce à Phing </p>
]]></content:encoded>
			<wfw:commentRss>http://labs.pimsworld.org/2009/01/phing-automatise-les-operations-repetitives-des-developpements-php/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
