Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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