Development

Documentation/fr_FR/book/trunk/15-Unit-and-Functional-Testing (diff)

You must first sign up to be able to contribute.

Changes between Version 7 and Version 8 of Documentation/fr_FR/book/trunk/15-Unit-and-Functional-Testing

Show
Ignore:
Author:
David.Bonnet (IP: 82.66.230.129)
Timestamp:
03/20/07 18:40:38 (11 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/fr_FR/book/trunk/15-Unit-and-Functional-Testing

    v7 v8  
    377377 
    378378<p class="figure">Listing 15-6 - Inclusion des Classes dans le fichier de test unitaire</p> 
    379  
    380 <pre class="php"><span class="kw2">&lt;?php</span> 
    381 &nbsp; 
    382 <span class="kw1">include</span><span class="br0">(</span><a href="http://www.php.net/dirname"><span class="kw3">dirname</span></a><span class="br0">(</span><span class="kw2">__FILE__</span><span class="br0">)</span>.<span class="st0">'/../bootstrap/unit.php'</span><span class="br0">)</span>; 
    383  
    384 <span class="kw1">include</span><span class="br0">(</span><a href="http://www.php.net/dirname"><span class="kw3">dirname</span></a><span class="br0">(</span><span class="kw2">__FILE__</span><span class="br0">)</span>.<span class="st0">'/../../config/config.php'</span><span class="br0">)</span>; 
    385 <span class="kw1">require_once</span><span class="br0">(</span><span class="re0">$sf_symfony_lib_dir</span>.<span class="st0">'/util/sfToolkit.class.php'</span><span class="br0">)</span>; 
    386  
    387 &nbsp; 
    388 <span class="re0">$t</span> = <span class="kw2">new</span> lime_test<span class="br0">(</span><span class="nu0">7</span>, <span class="kw2">new</span> lime_output_color<span class="br0">(</span><span class="br0">)</span><span class="br0">)</span>; 
    389  
    390 &nbsp; 
    391 <span class="co1">// isPathAbsolute()</span> 
    392 <span class="re0">$t</span>-&gt;<span class="me1">diag</span><span class="br0">(</span><span class="st0">'isPathAbsolute()'</span><span class="br0">)</span>; 
    393 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'/test'</span><span class="br0">)</span>, <span class="kw2">true</span>, 
    394     <span class="st0">'isPathAbsolute() returns true if path is absolute'</span><span class="br0">)</span>; 
    395  
    396 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'<span class="es0">\\</span>test'</span><span class="br0">)</span>, <span class="kw2">true</span>, 
    397     <span class="st0">'isPathAbsolute() returns true if path is absolute'</span><span class="br0">)</span>; 
    398  
    399 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'C:<span class="es0">\\</span>test'</span><span class="br0">)</span>, <span class="kw2">true</span>, 
    400     <span class="st0">'isPathAbsolute() returns true if path is absolute'</span><span class="br0">)</span>; 
    401  
    402 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'d:/test'</span><span class="br0">)</span>, <span class="kw2">true</span>, 
    403     <span class="st0">'isPathAbsolute() returns true if path is absolute'</span><span class="br0">)</span>; 
    404 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'test'</span><span class="br0">)</span>, <span class="kw2">false</span>, 
    405     <span class="st0">'isPathAbsolute() returns false if path is relative'</span><span class="br0">)</span>; 
    406  
    407 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'../test'</span><span class="br0">)</span>, <span class="kw2">false</span>, 
    408     <span class="st0">'isPathAbsolute() returns false if path is relative'</span><span class="br0">)</span>; 
    409 <span class="re0">$t</span>-&gt;<span class="me1">is</span><span class="br0">(</span>sfToolkit::<span class="me2">isPathAbsolute</span><span class="br0">(</span><span class="st0">'..<span class="es0">\\</span>test'</span><span class="br0">)</span>, <span class="kw2">false</span>, 
    410     <span class="st0">'isPathAbsolute() returns false if path is relative'</span><span class="br0">)</span>;</pre> 
     379}}} 
     380{{{ 
     381#!php 
     382<?php 
     383  
     384include(dirname(__FILE__).'/../bootstrap/unit.php'); 
     385include(dirname(__FILE__).'/../../config/config.php'); 
     386require_once($sf_symfony_lib_dir.'/util/sfToolkit.class.php'); 
     387  
     388$t = new lime_test(7, new lime_output_color()); 
     389  
     390// isPathAbsolute() 
     391$t->diag('isPathAbsolute()'); 
     392$t->is(sfToolkit::isPathAbsolute('/test'), true, 
     393    'isPathAbsolute() returns true if path is absolute'); 
     394$t->is(sfToolkit::isPathAbsolute('\\test'), true, 
     395    'isPathAbsolute() returns true if path is absolute'); 
     396$t->is(sfToolkit::isPathAbsolute('C:\\test'), true, 
     397    'isPathAbsolute() returns true if path is absolute'); 
     398$t->is(sfToolkit::isPathAbsolute('d:/test'), true, 
     399    'isPathAbsolute() returns true if path is absolute'); 
     400$t->is(sfToolkit::isPathAbsolute('test'), false, 
     401    'isPathAbsolute() returns false if path is relative'); 
     402$t->is(sfToolkit::isPathAbsolute('../test'), false, 
     403    'isPathAbsolute() returns false if path is relative'); 
     404$t->is(sfToolkit::isPathAbsolute('..\\test'), false, 
     405    'isPathAbsolute() returns false if path is relative'); 
     406}}} 
     407{{{ 
     408#!html 
    411409 
    412410<p>Dans les fichiers de tests unitaires, vous avez besoin d'instantier non seulement l'objet que vous examinez, mais également les objets dont ils dépendent au moment du test. Puisque les tests unitaires doivent demeurer indépendent des autres tests, cette indépendance peut faire échouer un test si une classe est cassée. En outre, l'installation de vrais objets peut être chère, en termes de lignes de code et en temps d'exécution. Maintenir dans l'esprit que la vitesse est cruciale dans le testeur unitaire parce qu'un développeur ce lassera rapidement d'un processus lent.</p> 
    413411 
    414412<p>Toutes les fois que vous commencez à inclure beaucoup de scrits pour un test d'unitaire, vous pouvez avoir besoin d'un simple système d'auto-chargement. À cette fin, la classe de <code>sfCore</code> (qui doit être manuellement incluse) fournit une méthode d'<code>initSimpleAutoload()</code>, qui attend un chemin absolu comme paramètre. Toutes les  classes situées sous ce chemin seront automatiquement chargées. Par exemple, si vous voulez avoir toutes les classes situées sous <code>$sf_symfony_lib_dir/util/</code>, commencez votre scrit de test comme ceci : </p> 
    415  
    416 <pre class="php"><span class="kw1">require_once</span><span class="br0">(</span><span class="re0">$sf_symfony_lib_dir</span>.<span class="st0">'/util/sfCore.class.php'</span><span class="br0">)</span>; 
    417 sfCore::<span class="me2">initSimpleAutoload</span><span class="br0">(</span><span class="re0">$sf_symfony_lib_dir</span>.<span class="st0">'/util'</span><span class="br0">)</span>;</pre> 
    418  
     413}}} 
     414{{{ 
     415#!php 
     416require_once($sf_symfony_lib_dir.'/util/sfCore.class.php'); 
     417sfCore::initSimpleAutoload($sf_symfony_lib_dir.'/util'); 
     418}}} 
     419{{{ 
     420#!html 
    419421<blockquote class="tip"><p> Le générateur objet Propel compte sur une longue cascade de classes, quand vous voudriez examiner l'objet Propel, l'auto-chargement sera nécessaire.Notez, pour que Propel travaille correctement, vous dervrez necessairement inclure les fichiers du répertoire <code>vendor/propel/</code> (ainsi l'appel à <code>sfCore</code> devient <code>sfCore::initSimpleAutoload(array(SF_ROOT_ DIR.'/lib/model', $sf_symfony_lib_dir.'/vendor/propel'));</code>) et pour ajouter le noyau de Propel au chemin d'inclusion (on fait  <code>set_include_path($sf_symfony_lib_dir.'/vendor'.PATH_SEPARATOR.SF_ROOT_DIR.PATH_SEPARATOR.get_include_path()</code>.</p> 
    420422</blockquote>