mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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.
This commit is contained in:
parent
42dccac8da
commit
cd6c370dd9
1 changed files with 33 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue