1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Fichier de test pour une class |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace BFW\test\unit; |
7
|
|
|
use \atoum; |
8
|
|
|
|
9
|
|
|
require_once(__DIR__.'/../common.php'); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Test de la class Observer |
13
|
|
|
*/ |
14
|
|
|
class Observer extends atoum |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var $class : Instance de la class Observer |
18
|
|
|
*/ |
19
|
|
|
protected $class; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var $mock : Instance du mock pour la class Observer |
23
|
|
|
*/ |
24
|
|
|
protected $mock; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Instanciation de la class avant chaque méthode de test |
28
|
|
|
*/ |
29
|
|
|
public function beforeTestMethod($testMethod) |
30
|
|
|
{ |
31
|
|
|
//$this->class = new \BFW\Observer(); |
32
|
|
|
$this->mock = new MockObserver(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Test de la méthode update($subject) |
37
|
|
|
*/ |
38
|
|
|
public function testUpdate() |
39
|
|
|
{ |
40
|
|
|
$subject = new MockObserverSplSubject; |
41
|
|
|
$this->mock->update($subject); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test de la méthode updateWithAction($subject, $action) |
46
|
|
|
* |
47
|
|
|
* @TODO : Too complexe actually |
48
|
|
|
*/ |
49
|
|
|
public function testUpdateWithAction() |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Mock pour les observers |
58
|
|
|
*/ |
59
|
|
|
class MockObserverSplSubject implements \SplSubject |
60
|
|
|
{ |
61
|
|
|
/** |
62
|
|
|
* Ajouter un nouvel observateur |
63
|
|
|
* |
64
|
|
|
* @param SplObserver $observer L'observateur à ajouter |
65
|
|
|
*/ |
66
|
|
|
public function attach(SplObserver $observer) |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Enlever un observateur |
73
|
|
|
* |
74
|
|
|
* @param SplObserver $observer L'observateur à enlever |
75
|
|
|
*/ |
76
|
|
|
public function detach(SplObserver $observer) |
77
|
|
|
{ |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Déclanche la notification vers les observers. |
83
|
|
|
*/ |
84
|
|
|
public function notify() |
85
|
|
|
{ |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Mock pour la classe Observer |
92
|
|
|
*/ |
93
|
|
|
class MockObserver extends \BFW\Observer |
94
|
|
|
{ |
95
|
|
|
/** |
96
|
|
|
* Accesseur get |
97
|
|
|
*/ |
98
|
|
|
public function __get($name) {return $this->$name;} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|