mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
make it possible to test for files that don't exist
This commit is contained in:
parent
d492c86ddc
commit
6ab5f1f2a2
2 changed files with 60 additions and 9 deletions
|
@ -337,10 +337,13 @@ class TestShell extends Shell {
|
|||
* Find the test case for the passed file. The file could itself be a test.
|
||||
*
|
||||
* @param mixed $file
|
||||
* @param mixed $category
|
||||
* @param mixed $throwOnMissingFile
|
||||
* @access protected
|
||||
* @return array(type, case)
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _mapFileToCase($file, $category) {
|
||||
protected function _mapFileToCase($file, $category, $throwOnMissingFile = true) {
|
||||
if (!$category || (substr($file, -4) !== '.php')) {
|
||||
return false;
|
||||
}
|
||||
|
@ -381,12 +384,11 @@ class TestShell extends Shell {
|
|||
$testCase[0] = strtoupper($testCase[0]);
|
||||
$testFile = CAKE . 'Test/Case/' . $testCase . 'Test.php';
|
||||
|
||||
if (file_exists($testFile)) {
|
||||
return $testCase;
|
||||
if (!file_exists($testFile) && $throwOnMissingFile) {
|
||||
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
|
||||
}
|
||||
|
||||
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
|
||||
return false;
|
||||
return $testCase;
|
||||
}
|
||||
|
||||
if ($category === 'app') {
|
||||
|
@ -399,9 +401,8 @@ class TestShell extends Shell {
|
|||
);
|
||||
}
|
||||
|
||||
if (!file_exists($testFile)) {
|
||||
if (!file_exists($testFile) && $throwOnMissingFile) {
|
||||
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
|
||||
return false;
|
||||
}
|
||||
|
||||
$testCase = substr($file, 0, -8);
|
||||
|
|
|
@ -20,6 +20,17 @@
|
|||
App::uses('ShellDispatcher', 'Console');
|
||||
App::uses('TestShell', 'Console/Command');
|
||||
|
||||
class TestTestShell extends TestShell {
|
||||
|
||||
public function mapFileToCase($file, $category, $throwOnMissingFile = true) {
|
||||
return $this->_mapFileToCase($file, $category, $throwOnMissingFile);
|
||||
}
|
||||
|
||||
public function mapFileToCategory($file) {
|
||||
return $this->_mapFileToCategory($file);
|
||||
}
|
||||
}
|
||||
|
||||
class TestShellTest extends CakeTestCase {
|
||||
|
||||
|
||||
|
@ -33,7 +44,7 @@ class TestShellTest extends CakeTestCase {
|
|||
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
||||
|
||||
$this->Shell = $this->getMock(
|
||||
'TestShell',
|
||||
'TestTestShell',
|
||||
array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'),
|
||||
array($out, $out, $in)
|
||||
);
|
||||
|
@ -49,6 +60,45 @@ class TestShellTest extends CakeTestCase {
|
|||
unset($this->Dispatch, $this->Shell);
|
||||
}
|
||||
|
||||
/**
|
||||
* testMapCoreFileToCategory
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMapCoreFileToCategory() {
|
||||
$this->Shell->startup();
|
||||
|
||||
$return = $this->Shell->mapFileToCategory('lib/Cake/basics.php');
|
||||
$this->assertSame('core', $return);
|
||||
|
||||
$return = $this->Shell->mapFileToCategory('lib/Cake/Core/App.php');
|
||||
$this->assertSame('core', $return);
|
||||
|
||||
$return = $this->Shell->mapFileToCategory('lib/Cake/Some/Deeply/Nested/Structure.php');
|
||||
$this->assertSame('core', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* testMapCoreFileToCase
|
||||
*
|
||||
* basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMapCoreFileToCase() {
|
||||
$this->Shell->startup();
|
||||
|
||||
$return = $this->Shell->mapFileToCase('lib/Cake/basics.php', 'core');
|
||||
$this->assertSame('Basics', $return);
|
||||
|
||||
$return = $this->Shell->mapFileToCase('lib/Cake/Core/App.php', 'core');
|
||||
$this->assertSame('Core/App', $return);
|
||||
|
||||
$return = $this->Shell->mapFileToCase('lib/Cake/Some/Deeply/Nested/Structure.php', 'core', false);
|
||||
$this->assertSame('Some/Deeply/Nested/Structure', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* test available list of test cases for an empty category
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue