1 | <?php |
||
14 | class CreateClasse extends atoum |
||
15 | { |
||
16 | /** |
||
17 | * @var $class : Instance de la class CreateClasse |
||
18 | */ |
||
19 | protected $class; |
||
20 | |||
21 | /** |
||
22 | * @var $mock : Instance du mock pour la class CreateClasse |
||
23 | */ |
||
24 | protected $mock; |
||
25 | |||
26 | /** |
||
27 | * Instanciation de la class avant chaque méthode de test |
||
28 | * |
||
29 | * @param string $testMethod |
||
30 | */ |
||
31 | public function beforeTestMethod($testMethod) |
||
32 | { |
||
33 | $this->class = new \BFW\CreateClasse('test'); |
||
34 | $this->mock = new MockCreateClasse('test'); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Test du constructeur : CreateClasse($nom, $options=array()) |
||
39 | */ |
||
40 | public function testCreateClasse() |
||
41 | { |
||
42 | $this->string($this->mock->indente)->isEqualTo(' '); |
||
43 | $this->string($this->mock->extends)->isEqualTo(''); |
||
44 | $this->array($this->mock->implements)->isEqualTo(array()); |
||
45 | |||
46 | $mock = new MockCreateClasse('test', array( |
||
47 | 'indente' => ' ', |
||
48 | 'extends' => 'myClass', |
||
49 | 'implements' => array('IMyClass') |
||
50 | )); |
||
51 | |||
52 | $this->string($mock->indente)->isEqualTo(' '); |
||
53 | $this->string($mock->extends)->isEqualTo('myClass'); |
||
54 | $this->array($mock->implements)->isEqualTo(array('IMyClass')); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Test de la méthode getFile() |
||
59 | */ |
||
60 | public function testGetFile() |
||
61 | { |
||
62 | $this->string($this->class->getFile())->isEqualTo(''); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Test de la méthode createAttribut($nom, $opt=array()) |
||
67 | */ |
||
68 | public function testCreateAttribut() |
||
69 | { |
||
70 | $this->boolean($this->mock->createAttribut('test'))->isTrue(); |
||
71 | $this->array($this->mock->attributs)->isEqualTo(array('test')); |
||
72 | $this->array($this->mock->attributs_porter)->isEqualTo(array('protected')); |
||
73 | $this->array($this->mock->attributs_option)->isEqualTo(array(array( |
||
74 | 'porter' => 'protected', |
||
75 | 'get' => 1, |
||
76 | 'set' => 1, |
||
77 | ))); |
||
78 | $this->array($this->mock->get)->isEqualTo(array('test')); |
||
79 | $this->array($this->mock->set)->isEqualTo(array('test')); |
||
80 | |||
81 | |||
82 | $this->boolean($this->mock->createAttribut('test2', array('porter' => 'public', 'get' => 0, 'set' => 0)))->isTrue(); |
||
83 | $this->array($this->mock->attributs)->isEqualTo(array('test', 'test2')); |
||
84 | $this->array($this->mock->attributs_porter)->isEqualTo(array('protected', 'public')); |
||
85 | $this->array($this->mock->attributs_option)->isEqualTo(array( |
||
86 | array( |
||
87 | 'porter' => 'protected', |
||
88 | 'get' => 1, |
||
89 | 'set' => 1, |
||
90 | ), |
||
91 | array( |
||
92 | 'porter' => 'public', |
||
93 | 'get' => 0, |
||
94 | 'set' => 0 |
||
95 | ) |
||
96 | )); |
||
97 | $this->array($this->mock->get)->isEqualTo(array('test')); |
||
98 | $this->array($this->mock->set)->isEqualTo(array('test')); |
||
99 | |||
100 | |||
101 | $this->boolean($this->mock->createAttribut('test'))->isFalse(); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Test de la méthode createMethode($nom, $porter='private') |
||
106 | */ |
||
107 | public function testCreateMethode() |
||
108 | { |
||
109 | $this->boolean($this->mock->createMethode('test'))->isTrue(); |
||
110 | $this->array($this->mock->methode)->isEqualTo(array('test')); |
||
111 | $this->array($this->mock->methode_porter)->isEqualTo(array('protected')); |
||
112 | |||
113 | $this->boolean($this->mock->createMethode('test2', 'public'))->isTrue(); |
||
114 | $this->array($this->mock->methode)->isEqualTo(array('test', 'test2')); |
||
115 | $this->array($this->mock->methode_porter)->isEqualTo(array('protected', 'public')); |
||
116 | |||
117 | $this->boolean($this->mock->createMethode('test'))->isFalse(); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Test de la méthode genereAttribut($key) |
||
122 | */ |
||
123 | public function testGenereAttribut() |
||
124 | { |
||
125 | $this->mock->createAttribut('test'); |
||
126 | $this->mock->genereAttribut(0); |
||
127 | |||
128 | $this->string($this->mock->file)->isEqualTo( |
||
129 | ' /**'."\n". |
||
130 | ' * @var $test : Ma description.'."\n". |
||
131 | ' */'."\n". |
||
132 | ' protected $test;'."\n\n" |
||
133 | ); |
||
134 | |||
135 | $this->beforeTestMethod(''); |
||
136 | $this->mock->createAttribut('test', array('default' => 'true')); |
||
137 | $this->mock->genereAttribut(0); |
||
138 | |||
139 | $this->string($this->mock->file)->isEqualTo( |
||
140 | ' /**'."\n". |
||
141 | ' * @var $test : Ma description. Par défaut à true.'."\n". |
||
142 | ' */'."\n". |
||
143 | ' protected $test = true;'."\n\n" |
||
144 | ); |
||
145 | |||
146 | $this->beforeTestMethod(''); |
||
147 | $this->mock->createAttribut('test', array('default' => 'monTest', 'default_string' => true)); |
||
148 | $this->mock->genereAttribut(0); |
||
149 | |||
150 | $this->string($this->mock->file)->isEqualTo( |
||
151 | ' /**'."\n". |
||
152 | ' * @var $test : Ma description. Par défaut à \'monTest\'.'."\n". |
||
153 | ' */'."\n". |
||
154 | ' protected $test = \'monTest\';'."\n\n" |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Test de la méthode genereGet($key) |
||
160 | */ |
||
161 | public function testGenereGet() |
||
162 | { |
||
163 | $this->mock->createAttribut('test'); |
||
164 | $this->mock->genereGet(0); |
||
165 | |||
166 | $this->string($this->mock->file)->isEqualTo( |
||
167 | ' /**'."\n". |
||
168 | ' * Accesseur get vers test'."\n". |
||
169 | ' *'."\n". |
||
170 | ' * @return mixed : La valeur de test'."\n". |
||
171 | ' */'."\n". |
||
172 | ' public function get_test() {return $this->test;}'."\n\n" |
||
173 | ); |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Test de la méthode genereSet($key) |
||
178 | */ |
||
179 | public function testGenereSet() |
||
180 | { |
||
181 | $this->mock->createAttribut('test'); |
||
182 | $this->mock->genereSet(0); |
||
183 | |||
184 | $this->string($this->mock->file)->isEqualTo( |
||
185 | ' /**'."\n". |
||
186 | ' * Accesseur set vers test'."\n". |
||
187 | ' *'."\n". |
||
188 | ' * @param mixed : La nouvelle valeur de test'."\n". |
||
189 | ' *'."\n". |
||
190 | ' * @return bool : True si réussi, False sinon.'."\n". |
||
191 | ' */'."\n". |
||
192 | ' public function set_test($data) {return ($this->test = $data) ? true : false;}'."\n\n" |
||
193 | ); |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * Test de la méthode genereMethode($key) |
||
198 | */ |
||
199 | public function testGenereMethode() |
||
200 | { |
||
201 | $this->mock->createMethode('test'); |
||
202 | $this->mock->genereMethode(0); |
||
203 | |||
204 | $this->string($this->mock->file)->isEqualTo( |
||
205 | ' /**'."\n". |
||
206 | ' * Description de ma méthode.'."\n". |
||
207 | ' */'."\n". |
||
208 | ' protected function test() {}'."\n" |
||
209 | ); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * Test de la méthode genere() |
||
214 | */ |
||
215 | public function testGenere() |
||
216 | { |
||
217 | $this->mock = new MockCreateClasse('test', array( |
||
218 | 'extends' => 'myClass', |
||
219 | 'implements' => array('IMyClass') |
||
220 | )); |
||
221 | |||
222 | $this->mock->createAttribut('test'); |
||
223 | $this->mock->createMethode('test'); |
||
224 | |||
225 | $this->mock->genere(); |
||
226 | $this->string($this->mock->file)->isEqualTo( |
||
227 | '<?php'."\n". |
||
228 | '/**'."\n". |
||
229 | ' * Ma description du fichier'."\n". |
||
230 | ' * @author me'."\n". |
||
231 | ' * @version 1.0'."\n". |
||
232 | ' */'."\n". |
||
233 | ''."\n". |
||
234 | '/**'."\n". |
||
235 | ' * La description de ma classe'."\n". |
||
236 | ' * @package MonProjet'."\n". |
||
237 | ' */'."\n". |
||
238 | 'class test extends myClass implements IMyClass'."\n". |
||
239 | '{'."\n". |
||
240 | ' /**'."\n". |
||
241 | ' * @var $test : Ma description.'."\n". |
||
242 | ' */'."\n". |
||
243 | ' protected $test;'."\n". |
||
244 | ''."\n". |
||
245 | ''."\n". |
||
246 | ' /**'."\n". |
||
247 | ' * Constructeur de la classe'."\n". |
||
248 | ' */'."\n". |
||
249 | ' public function __construct() {}'."\n". |
||
250 | ''."\n". |
||
251 | ' /**'."\n". |
||
252 | ' * Accesseur get vers test'."\n". |
||
253 | ' *'."\n". |
||
254 | ' * @return mixed : La valeur de test'."\n". |
||
255 | ' */'."\n". |
||
256 | ' public function get_test() {return $this->test;}'."\n". |
||
257 | ''."\n". |
||
258 | ' /**'."\n". |
||
259 | ' * Accesseur set vers test'."\n". |
||
260 | ' *'."\n". |
||
261 | ' * @param mixed : La nouvelle valeur de test'."\n". |
||
262 | ' *'."\n". |
||
263 | ' * @return bool : True si réussi, False sinon.'."\n". |
||
264 | ' */'."\n". |
||
265 | ' public function set_test($data) {return ($this->test = $data) ? true : false;}'."\n". |
||
266 | ''."\n". |
||
267 | ' /**'."\n". |
||
268 | ' * Description de ma méthode.'."\n". |
||
269 | ' */'."\n". |
||
270 | ' protected function test() {}'."\n". |
||
271 | '}'."\n". |
||
272 | '?>' |
||
273 | ); |
||
274 | } |
||
275 | |||
276 | } |
||
277 | |||
329 |