Skip to content

Commit

Permalink
simplify path logic
Browse files Browse the repository at this point in the history
we know the category - use it to simplify some regexs
  • Loading branch information
AD7six committed May 28, 2011
1 parent dcf14a7 commit 8b1045a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/Cake/Console/Command/TestShell.php
Expand Up @@ -337,6 +337,11 @@ protected function _mapFileToCase($file, $category) {
return false;
}

$_file = realpath($file);
if ($_file) {
$file = $_file;
}

$testFile = $testCase = null;

if (preg_match('@Test[\\\/]@', $file)) {
Expand Down Expand Up @@ -376,11 +381,15 @@ protected function _mapFileToCase($file, $category) {
return false;
}

$testFile = preg_replace(
'@(.*)((?:(?:Config|Console|Controller|Lib|Locale|Model|plugins|Plugin|Test|Vendor|View|webroot)[\\\/]).*$|App[-a-z]*$)@',
'\1Test/Case/\2Test.php',
$file
);
if ($category === 'app') {
$testFile = str_replace(APP, APP . 'Test/Case/', $file) . 'Test.php';
} else {
$testFile = preg_replace(
"@((?:plugins|Plugin)[\\/]{$category}[\\/])(.*)$@",
'\1Test/Case/\2Test.php',
$file
);
}

if (!file_exists($testFile)) {
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
Expand Down

0 comments on commit 8b1045a

Please sign in to comment.