| 60 | jpm | 1 | <?php
 | 
        
           | 95 | jpm | 2 | // declare(encoding='UTF-8');
 | 
        
           |  |  | 3 | /**
 | 
        
           |  |  | 4 |  * Classe contenant des méthodes :
 | 
        
           |  |  | 5 |  *  - d'intialisation des tests,
 | 
        
           |  |  | 6 |  *  - refactorisant le code des tests,
 | 
        
           |  |  | 7 |  *  - facilitant les tests.
 | 
        
           |  |  | 8 |  *
 | 
        
           |  |  | 9 |  * @category	php 5.3
 | 
        
           |  |  | 10 |  * @package		Tests/Scripts
 | 
        
           |  |  | 11 |  * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
 | 
        
           |  |  | 12 |  * @copyright	Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
 | 
        
           |  |  | 13 |  * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
 | 
        
           |  |  | 14 |  * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
 | 
        
           |  |  | 15 |  * @version		$Id$
 | 
        
           |  |  | 16 |  */
 | 
        
           | 94 | jpm | 17 | abstract class ScriptEflorePhpUnit extends PHPUnit_Framework_TestCase {
 | 
        
           | 60 | jpm | 18 |   | 
        
           |  |  | 19 | 	public static function setUpBeforeClass() {
 | 
        
           |  |  | 20 | 		error_reporting(E_ALL);
 | 
        
           | 94 | jpm | 21 |   | 
        
           |  |  | 22 | 		self::chargerFramework();
 | 
        
           |  |  | 23 | 	}
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | 	private static function chargerFramework() {
 | 
        
           | 64 | jpm | 26 | 		$cheminRacine = realpath(dirname(__FILE__).'/../').'/';
 | 
        
           | 60 | jpm | 27 | 		$framework =  $cheminRacine.'framework.php';
 | 
        
           |  |  | 28 | 		if (!file_exists($framework)) {
 | 
        
           |  |  | 29 | 			$e = "Veuillez paramétrer l'emplacement et la version du Framework dans le fichier $framework";
 | 
        
           |  |  | 30 | 			trigger_error($e, E_USER_ERROR);
 | 
        
           |  |  | 31 | 		} else {
 | 
        
           |  |  | 32 | 			// Inclusion du Framework
 | 
        
           |  |  | 33 | 			require_once $framework;
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | 			// Ajout d'information concernant cette application
 | 
        
           |  |  | 36 | 			Framework::setCheminAppli($cheminRacine);// Obligatoire
 | 
        
           |  |  | 37 | 		}
 | 
        
           |  |  | 38 | 	}
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | 	//+------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 41 | 	// Méthodes facilitant les tests
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 | 	/**
 | 
        
           |  |  | 44 | 	* Récupère un bouchon de classe abstraite.
 | 
        
           |  |  | 45 | 	* Comment l'utiliser :
 | 
        
           |  |  | 46 | 	* 	$classeAstraite = $this->getClasseAbstraite('MaClasse', array('param1', 'param2'));
 | 
        
           |  |  | 47 | 	*   $foo = $classeAstraite->methodeConcretePublique();
 | 
        
           |  |  | 48 | 	*
 | 
        
           |  |  | 49 | 	* @param String $classeNom Le nom de la classe
 | 
        
           |  |  | 50 | 	* @param Array $parametres Les paramètres à passer au constructeur.
 | 
        
           |  |  | 51 | 	* @return Object Le bouchon de la classe abstraite
 | 
        
           |  |  | 52 | 	*/
 | 
        
           |  |  | 53 | 	public function getClasseAbstraite($classeNom, Array $parametres) {
 | 
        
           |  |  | 54 | 		$efloreScript = $this->getMockForAbstractClass($classeNom, $parametres);
 | 
        
           |  |  | 55 | 		return $efloreScript;
 | 
        
           |  |  | 56 | 	}
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | 	/**
 | 
        
           |  |  | 59 | 	 * Récupère une méthode privée d'une classe pour tester/documenter.
 | 
        
           |  |  | 60 | 	 * Comment l'utiliser :
 | 
        
           |  |  | 61 | 	 * 	MyClass->foo():
 | 
        
           |  |  | 62 | 	 *   $cls = new MyClass();
 | 
        
           |  |  | 63 | 	 *   $foo = self::getPrivateMethode($cls, 'foo');
 | 
        
           |  |  | 64 | 	 *   $foo->invoke($cls, $...);
 | 
        
           |  |  | 65 | 	 *
 | 
        
           |  |  | 66 | 	 * @param object $objet Une instance de votre classe
 | 
        
           |  |  | 67 | 	 * @param string $methode Le nom de la méthode private
 | 
        
           |  |  | 68 | 	 * @return ReflectionMethod La méthode demandée
 | 
        
           |  |  | 69 | 	 */
 | 
        
           |  |  | 70 | 	public static function getPrivateMethode($objet, $nomMethode) {
 | 
        
           |  |  | 71 | 		$classe = new ReflectionClass($objet);
 | 
        
           |  |  | 72 | 		$methode = $classe->getMethod($nomMethode);
 | 
        
           |  |  | 73 | 		$methode->setAccessible(true);
 | 
        
           |  |  | 74 | 		return $methode;
 | 
        
           |  |  | 75 | 	}
 | 
        
           |  |  | 76 |   | 
        
           |  |  | 77 | 	/**
 | 
        
           |  |  | 78 | 	* Récupère une méthode protégée d'une classe pour tester/documenter.
 | 
        
           |  |  | 79 | 	* Comment l'utiliser :
 | 
        
           |  |  | 80 | 	* 	MyClass->foo():
 | 
        
           |  |  | 81 | 	*   $cls = new MyClass();
 | 
        
           |  |  | 82 | 	*   $foo = self::getProtectedMethode($cls, 'foo');
 | 
        
           |  |  | 83 | 	*   $foo->invoke($cls, $...);
 | 
        
           |  |  | 84 | 	* @param object $objet Une instance de votre classe
 | 
        
           |  |  | 85 | 	* @param string $methode Le nom de la méthode protected
 | 
        
           |  |  | 86 | 	* @return ReflectionMethod La méthode demandée
 | 
        
           |  |  | 87 | 	*/
 | 
        
           |  |  | 88 | 	public static function getProtectedMethode($objet, $nomMethode) {
 | 
        
           |  |  | 89 | 		return self::getPrivateMethode($objet, $nomMethode);
 | 
        
           |  |  | 90 | 	}
 | 
        
           |  |  | 91 | }
 | 
        
           |  |  | 92 | ?>
 |