diff --git a/lib/Cake/Console/Command/UpgradeShell.php b/lib/Cake/Console/Command/UpgradeShell.php index 84888de57..a6c5287cf 100644 --- a/lib/Cake/Console/Command/UpgradeShell.php +++ b/lib/Cake/Console/Command/UpgradeShell.php @@ -92,6 +92,29 @@ class UpgradeShell extends Shell { } } +/** + * 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 @@ class UpgradeShell extends Shell { $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 @@ class UpgradeShell extends Shell { 'Lib' => array('checkFolder' => false), 'Model', 'models', + 'Test' => array('regex' => '@class (\S*Test) extends CakeTestCase@'), 'tests', 'View', 'views', @@ -154,6 +181,7 @@ class UpgradeShell extends Shell { $defaultOptions = array( 'recursive' => true, 'checkFolder' => true, + 'regex' => '@class (\S*) .*{@' ); foreach($sourceDirs as $dir => $options) { if (is_numeric($dir)) { @@ -513,7 +541,7 @@ class UpgradeShell extends Shell { $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 @@ class UpgradeShell extends Shell { '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