統計
| ブランチ: | リビジョン:

pictcode / lib / Cake / Test / Case / Console / Command / TestShellTest.php @ 635eef61

履歴 | 表示 | アノテート | ダウンロード (9.939 KB)

1 635eef61 spyder1211
<?php
2
/**
3
 * TestSuiteShell test case
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP(tm) Project
14
 * @package       Cake.Test.Case.Console.Command
15
 * @since         CakePHP(tm) v 2.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
19
App::uses('ShellDispatcher', 'Console');
20
App::uses('TestShell', 'Console/Command');
21
22
/**
23
 * Class TestTestShell
24
 *
25
 * @package       Cake.Test.Case.Console.Command
26
 */
27
class TestTestShell extends TestShell {
28
29
        public function mapFileToCase($file, $category, $throwOnMissingFile = true) {
30
                return $this->_mapFileToCase($file, $category, $throwOnMissingFile);
31
        }
32
33
        public function mapFileToCategory($file) {
34
                return $this->_mapFileToCategory($file);
35
        }
36
37
}
38
39
/**
40
 * Class TestShellTest
41
 *
42
 * @package       Cake.Test.Case.Console.Command
43
 */
44
class TestShellTest extends CakeTestCase {
45
46
/**
47
 * setUp test case
48
 *
49
 * @return void
50
 */
51
        public function setUp() {
52
                parent::setUp();
53
                $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
54
                $in = $this->getMock('ConsoleInput', array(), array(), '', false);
55
56
                $this->Shell = $this->getMock(
57
                        'TestTestShell',
58
                        array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'),
59
                        array($out, $out, $in)
60
                );
61
                $this->Shell->OptionParser = $this->getMock('ConsoleOptionParser', array(), array(null, false));
62
        }
63
64
/**
65
 * tearDown method
66
 *
67
 * @return void
68
 */
69
        public function tearDown() {
70
                parent::tearDown();
71
                unset($this->Dispatch, $this->Shell);
72
        }
73
74
/**
75
 * testMapCoreFileToCategory
76
 *
77
 * @return void
78
 */
79
        public function testMapCoreFileToCategory() {
80
                $this->Shell->startup();
81
82
                $return = $this->Shell->mapFileToCategory('lib/Cake/basics.php');
83
                $this->assertSame('core', $return);
84
85
                $return = $this->Shell->mapFileToCategory('lib/Cake/Core/App.php');
86
                $this->assertSame('core', $return);
87
88
                $return = $this->Shell->mapFileToCategory('lib/Cake/Some/Deeply/Nested/Structure.php');
89
                $this->assertSame('core', $return);
90
        }
91
92
/**
93
 * testMapCoreFileToCase
94
 *
95
 * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
96
 *
97
 * @return void
98
 */
99
        public function testMapCoreFileToCase() {
100
                $this->Shell->startup();
101
102
                $return = $this->Shell->mapFileToCase('lib/Cake/basics.php', 'core');
103
                $this->assertSame('Basics', $return);
104
105
                $return = $this->Shell->mapFileToCase('lib/Cake/Core/App.php', 'core');
106
                $this->assertSame('Core/App', $return);
107
108
                $return = $this->Shell->mapFileToCase('lib/Cake/Some/Deeply/Nested/Structure.php', 'core', false);
109
                $this->assertSame('Some/Deeply/Nested/Structure', $return);
110
        }
111
112
/**
113
 * testMapAppFileToCategory
114
 *
115
 * @return void
116
 */
117
        public function testMapAppFileToCategory() {
118
                $this->Shell->startup();
119
120
                $return = $this->Shell->mapFileToCategory(APP . 'Controller/ExampleController.php');
121
                $this->assertSame('app', $return);
122
123
                $return = $this->Shell->mapFileToCategory(APP . 'My/File/Is/Here.php');
124
                $this->assertSame('app', $return);
125
        }
126
127
/**
128
 * testMapAppFileToCase
129
 *
130
 * @return void
131
 */
132
        public function testMapAppFileToCase() {
133
                $this->Shell->startup();
134
135
                $return = $this->Shell->mapFileToCase(APP . 'Controller/ExampleController.php', 'app', false);
136
                $this->assertSame('Controller/ExampleController', $return);
137
138
                $return = $this->Shell->mapFileToCase(APP . 'My/File/Is/Here.php', 'app', false);
139
                $this->assertSame('My/File/Is/Here', $return);
140
        }
141
142
/**
143
 * testMapPluginFileToCategory
144
 *
145
 * @return void
146
 */
147
        public function testMapPluginFileToCategory() {
148
                $this->Shell->startup();
149
150
                $return = $this->Shell->mapFileToCategory(APP . 'Plugin/awesome/Controller/ExampleController.php');
151
                $this->assertSame('awesome', $return);
152
153
                $return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php');
154
                $this->assertSame('awesome', $return);
155
        }
156
157
/**
158
 * testMapPluginFileToCase
159
 *
160
 * @return void
161
 */
162
        public function testMapPluginFileToCase() {
163
                $this->Shell->startup();
164
165
                $return = $this->Shell->mapFileToCase(APP . 'Plugin/awesome/Controller/ExampleController.php', 'awesome', false);
166
                $this->assertSame('Controller/ExampleController', $return);
167
168
                $return = $this->Shell->mapFileToCase(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php', 'awesome', false);
169
                $this->assertSame('Controller/ExampleController', $return);
170
        }
171
172
/**
173
 * testMapCoreTestToCategory
174
 *
175
 * @return void
176
 */
177
        public function testMapCoreTestToCategory() {
178
                $this->Shell->startup();
179
180
                $return = $this->Shell->mapFileToCategory('lib/Cake/Test/Case/BasicsTest.php');
181
                $this->assertSame('core', $return);
182
183
                $return = $this->Shell->mapFileToCategory('lib/Cake/Test/Case/BasicsTest.php');
184
                $this->assertSame('core', $return);
185
186
                $return = $this->Shell->mapFileToCategory('lib/Cake/Test/Case/Some/Deeply/Nested/StructureTest.php');
187
                $this->assertSame('core', $return);
188
        }
189
190
/**
191
 * testMapCoreTestToCase
192
 *
193
 * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
194
 *
195
 * @return void
196
 */
197
        public function testMapCoreTestToCase() {
198
                $this->Shell->startup();
199
200
                $return = $this->Shell->mapFileToCase('lib/Cake/Test/Case/BasicsTest.php', 'core');
201
                $this->assertSame('Basics', $return);
202
203
                $return = $this->Shell->mapFileToCase('lib/Cake/Test/Case/Core/AppTest.php', 'core');
204
                $this->assertSame('Core/App', $return);
205
206
                $return = $this->Shell->mapFileToCase('lib/Cake/Test/Case/Some/Deeply/Nested/StructureTest.php', 'core', false);
207
                $this->assertSame('Some/Deeply/Nested/Structure', $return);
208
        }
209
210
/**
211
 * testMapAppTestToCategory
212
 *
213
 * @return void
214
 */
215
        public function testMapAppTestToCategory() {
216
                $this->Shell->startup();
217
218
                $return = $this->Shell->mapFileToCategory(APP . 'Test/Case/Controller/ExampleControllerTest.php');
219
                $this->assertSame('app', $return);
220
221
                $return = $this->Shell->mapFileToCategory(APP . 'Test/Case/My/File/Is/HereTest.php');
222
                $this->assertSame('app', $return);
223
        }
224
225
/**
226
 * testMapAppTestToCase
227
 *
228
 * @return void
229
 */
230
        public function testMapAppTestToCase() {
231
                $this->Shell->startup();
232
233
                $return = $this->Shell->mapFileToCase(APP . 'Test/Case/Controller/ExampleControllerTest.php', 'app', false);
234
                $this->assertSame('Controller/ExampleController', $return);
235
236
                $return = $this->Shell->mapFileToCase(APP . 'Test/Case/My/File/Is/HereTest.php', 'app', false);
237
                $this->assertSame('My/File/Is/Here', $return);
238
        }
239
240
/**
241
 * testMapPluginTestToCategory
242
 *
243
 * @return void
244
 */
245
        public function testMapPluginTestToCategory() {
246
                $this->Shell->startup();
247
248
                $return = $this->Shell->mapFileToCategory(APP . 'Plugin/awesome/Test/Case/Controller/ExampleControllerTest.php');
249
                $this->assertSame('awesome', $return);
250
251
                $return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php');
252
                $this->assertSame('awesome', $return);
253
        }
254
255
/**
256
 * testMapPluginTestToCase
257
 *
258
 * @return void
259
 */
260
        public function testMapPluginTestToCase() {
261
                $this->Shell->startup();
262
263
                $return = $this->Shell->mapFileToCase(APP . 'Plugin/awesome/Test/Case/Controller/ExampleControllerTest.php', 'awesome', false);
264
                $this->assertSame('Controller/ExampleController', $return);
265
266
                $return = $this->Shell->mapFileToCase(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php', 'awesome', false);
267
                $this->assertSame('Controller/ExampleController', $return);
268
        }
269
270
/**
271
 * testMapNotTestToNothing
272
 *
273
 * @return void
274
 */
275
        public function testMapNotTestToNothing() {
276
                $this->Shell->startup();
277
278
                $return = $this->Shell->mapFileToCategory(APP . 'Test/Case/NotATestFile.php');
279
                $this->assertSame('app', $return);
280
281
                $return = $this->Shell->mapFileToCase(APP . 'Test/Case/NotATestFile.php', false, false);
282
                $this->assertFalse($return);
283
284
                $return = $this->Shell->mapFileToCategory(APP . 'Test/Fixture/SomeTest.php');
285
                $this->assertSame('app', $return);
286
287
                $return = $this->Shell->mapFileToCase(APP . 'Test/Fixture/SomeTest.php', false, false);
288
                $this->assertFalse($return);
289
        }
290
291
/**
292
 * test available list of test cases for an empty category
293
 *
294
 * @return void
295
 */
296
        public function testAvailableWithEmptyList() {
297
                $this->Shell->startup();
298
                $this->Shell->args = array('unexistant-category');
299
                $this->Shell->expects($this->at(0))->method('out')->with(__d('cake_console', "No test cases available \n\n"));
300
                $this->Shell->OptionParser->expects($this->once())->method('help');
301
                $this->Shell->available();
302
        }
303
304
/**
305
 * test available list of test cases for core category
306
 *
307
 * @return void
308
 */
309
        public function testAvailableCoreCategory() {
310
                $this->Shell->startup();
311
                $this->Shell->args = array('core');
312
                $this->Shell->expects($this->at(0))->method('out')->with('Core Test Cases:');
313
                $this->Shell->expects($this->at(1))->method('out')
314
                        ->with($this->stringContains('[1]'));
315
                $this->Shell->expects($this->at(2))->method('out')
316
                        ->with($this->stringContains('[2]'));
317
318
                $this->Shell->expects($this->once())->method('in')
319
                        ->with(__d('cake_console', 'What test case would you like to run?'), null, 'q')
320
                        ->will($this->returnValue('1'));
321
322
                $this->Shell->expects($this->once())->method('_run');
323
                $this->Shell->available();
324
                $this->assertEquals(array('core', 'AllBehaviors'), $this->Shell->args);
325
        }
326
327
/**
328
 * Tests that correct option for test runner are passed
329
 *
330
 * @return void
331
 */
332
        public function testRunnerOptions() {
333
                $this->Shell->startup();
334
                $this->Shell->args = array('core', 'Basics');
335
                $this->Shell->params = array('filter' => 'myFilter', 'colors' => true, 'verbose' => true);
336
337
                $this->Shell->expects($this->once())->method('_run')
338
                        ->with(
339
                                array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'),
340
                                array('--filter', 'myFilter', '--colors', '--verbose')
341
                        );
342
                $this->Shell->main();
343
        }
344
}