Skip to content

Commit 80670d8

Browse files
committed
Updating TestSuite shell to use refactored classes and methods in the TestSuite.
1 parent b58f03b commit 80670d8

File tree

1 file changed

+54
-37
lines changed

1 file changed

+54
-37
lines changed

cake/console/libs/testsuite.php

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -100,41 +100,64 @@ function initialize() {
100100
foreach ($plugins as $p) {
101101
$this->plugins[] = Inflector::underscore($p);
102102
}
103+
$this->parseArgs();
104+
$this->getManager();
103105
}
104106

105107
/**
106-
* Main entry point to this shell
108+
* Parse the arguments given into the Shell object properties.
107109
*
108110
* @return void
109111
* @access public
110112
*/
111-
function main() {
112-
$this->out($this->headline);
113-
$this->hr();
113+
function parseArgs() {
114+
$this->category = $this->args[0];
114115

115-
if (count($this->args) > 0) {
116-
$this->category = $this->args[0];
116+
if (!in_array($this->category, array('app', 'core'))) {
117+
$this->isPluginTest = true;
118+
}
117119

118-
if (!in_array($this->category, array('app', 'core'))) {
119-
$this->isPluginTest = true;
120-
}
120+
if (isset($this->args[1])) {
121+
$this->type = $this->args[1];
122+
}
121123

122-
if (isset($this->args[1])) {
123-
$this->type = $this->args[1];
124+
if (isset($this->args[2])) {
125+
if ($this->args[2] == 'cov') {
126+
$this->doCoverage = true;
127+
} else {
128+
$this->file = Inflector::underscore($this->args[2]);
124129
}
130+
}
125131

126-
if (isset($this->args[2])) {
127-
if ($this->args[2] == 'cov') {
128-
$this->doCoverage = true;
129-
} else {
130-
$this->file = Inflector::underscore($this->args[2]);
131-
}
132-
}
132+
if (isset($this->args[3]) && $this->args[3] == 'cov') {
133+
$this->doCoverage = true;
134+
}
135+
}
133136

134-
if (isset($this->args[3]) && $this->args[3] == 'cov') {
135-
$this->doCoverage = true;
136-
}
137-
} else {
137+
/**
138+
* Gets a manager instance, and set the app/plugin properties.
139+
*
140+
* @return void
141+
*/
142+
function getManager() {
143+
$this->Manager = new TestManager();
144+
$this->Manager->appTest = ($this->category === 'app');
145+
if ($this->isPluginTest) {
146+
$this->Manager->pluginTest = $this->category;
147+
}
148+
}
149+
150+
/**
151+
* Main entry point to this shell
152+
*
153+
* @return void
154+
* @access public
155+
*/
156+
function main() {
157+
$this->out($this->headline);
158+
$this->hr();
159+
160+
if (count($this->args) == 0) {
138161
$this->err('Sorry, you did not pass any arguments!');
139162
}
140163

@@ -252,11 +275,10 @@ function __canRun() {
252275
* @access private
253276
*/
254277
function __run() {
255-
$reporter = new CLIReporter();
256-
$this->__setGetVars();
278+
$Reporter = new CakeCliReporter();
257279

258280
if ($this->type == 'all') {
259-
return TestManager::runAllTests($reporter);
281+
return $this->Manager->runAllTests($Reporter);
260282
}
261283

262284
if ($this->doCoverage) {
@@ -278,9 +300,9 @@ function __run() {
278300

279301
if ($this->doCoverage) {
280302
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
281-
CodeCoverageManager::start($ucFirstGroup, $reporter);
303+
CodeCoverageManager::start($ucFirstGroup, $Reporter);
282304
}
283-
$result = TestManager::runGroupTest($ucFirstGroup, $reporter);
305+
$result = $this->Manager->runGroupTest($ucFirstGroup, $Reporter);
284306
if ($this->doCoverage) {
285307
CodeCoverageManager::report();
286308
}
@@ -301,10 +323,10 @@ function __run() {
301323

302324
if ($this->doCoverage) {
303325
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
304-
CodeCoverageManager::start($case, $reporter);
326+
CodeCoverageManager::start($case, $Reporter);
305327
}
306328

307-
$result = TestManager::runTestCase($case, $reporter);
329+
$result = $this->Manager->runTestCase($case, $Reporter);
308330
if ($this->doCoverage) {
309331
CodeCoverageManager::report();
310332
}
@@ -328,14 +350,9 @@ function __findFolderByCategory($category) {
328350
if (array_key_exists($category, $paths)) {
329351
$folder = $paths[$category] . 'tests';
330352
} else {
331-
$scoredCategory = Inflector::underscore($category);
332-
$folder = APP . 'plugins' . DS . $scoredCategory . DS;
333-
$pluginPaths = App::path('plugins');
334-
foreach ($pluginPaths as $path) {
335-
if (file_exists($path . $scoredCategory . DS . 'tests')) {
336-
$folder = $path . $scoredCategory . DS . 'tests';
337-
break;
338-
}
353+
$pluginPath = App::pluginPath($category);
354+
if (is_dir($pluginPath . 'tests')) {
355+
$folder = $pluginPath . 'tests' . DS;
339356
}
340357
}
341358
return $folder;

0 commit comments

Comments
 (0)