Skip to content
Permalink
Browse files

Adding `tests` method to Upgrade shell, fixing FooTestCase to FooTest.

Also making sure the preg_match matches the right class and not move the file to other directory rather than tests.
The method `tests` need to be run before `locations` to work properly.
  • Loading branch information...
renan committed Sep 14, 2011
1 parent 42dccac commit cd6c370dd93708ce641b2af0f334dd7764b50735
Showing with 33 additions and 1 deletion.
  1. +33 −1 lib/Cake/Console/Command/UpgradeShell.php
@@ -92,6 +92,29 @@ public function all() {
}
}
/**
* Update tests.
*
* - Update tests class names to FooTest rather than FooTestCase.
*
* @return void
*/
public function tests() {
$this->_paths = array(APP . 'tests' . DS);
if (!empty($this->params['plugin'])) {
$this->_paths = App::pluginPath($this->params['plugin']) . 'tests' . DS;
}
$patterns = array(
array(
'*TestCase extends CakeTestCase to *Test extends CakeTestCase',
'/([a-zA-Z]*Test)Case extends CakeTestCase/',
'\1 extends CakeTestCase'
),
);
$this->_filesRegexpUpdate($patterns);
}
/**
* Move files and folders to their new homes
*
@@ -122,6 +145,9 @@ public function locations() {
$moves = array(
'libs' => 'Lib',
'tests' => 'Test',
'Test' . DS . 'cases' => 'Test' . DS . 'Case',
'Test' . DS . 'fixtures' => 'Test' . DS . 'Fixture',
'vendors' . DS . 'shells' . DS . 'templates' => 'Console' . DS . 'Templates',
);
foreach($moves as $old => $new) {
@@ -145,6 +171,7 @@ public function locations() {
'Lib' => array('checkFolder' => false),
'Model',
'models',
'Test' => array('regex' => '@class (\S*Test) extends CakeTestCase@'),
'tests',
'View',
'views',
@@ -154,6 +181,7 @@ public function locations() {
$defaultOptions = array(
'recursive' => true,
'checkFolder' => true,
'regex' => '@class (\S*) .*{@'
);
foreach($sourceDirs as $dir => $options) {
if (is_numeric($dir)) {
@@ -513,7 +541,7 @@ protected function _movePhpFiles($path, $options) {
$file = $cwd . DS . $file;
$contents = file_get_contents($file);
preg_match('@class (\S*) .*{@', $contents, $match);
preg_match($options['regex'], $contents, $match);
if (!$match) {
continue;
}
@@ -665,6 +693,10 @@ public function getOptionParser() {
'help' => __d('cake_console', 'Run all upgrade commands.'),
'parser' => $subcommandParser
))
->addSubcommand('tests', array(
'help' => __d('cake_console', 'Update tests class names to FooTest rather than FooTestCase.'),
'parser' => $subcommandParser
))
->addSubcommand('locations', array(
'help' => __d('cake_console', 'Move files and folders to their new homes.'),
'parser' => $subcommandParser

0 comments on commit cd6c370

Please sign in to comment.
You can’t perform that action at this time.