Fix most coding standards issues in Test/Console

This commit is contained in:
mark_story 2012-03-10 23:32:02 -05:00
parent fdcb3dc34f
commit ed1d34accc
15 changed files with 54 additions and 50 deletions

View file

@ -28,7 +28,9 @@ App::uses('Controller', 'Controller');
if (!class_exists('UsersController')) {
class UsersController extends Controller {
public $name = 'Users';
}
}
@ -89,7 +91,7 @@ class BakeShellTest extends CakeTestCase {
$this->Shell->Model->expects($this->never())
->method('getName');
$this->Shell->Model->expects($this->once())
->method('bake')
->will($this->returnValue(true));
@ -97,7 +99,7 @@ class BakeShellTest extends CakeTestCase {
$this->Shell->Controller->expects($this->once())
->method('bake')
->will($this->returnValue(true));
$this->Shell->View->expects($this->once())
->method('execute');

View file

@ -24,14 +24,17 @@ App::uses('Shell', 'Console');
class TestStringOutput extends ConsoleOutput {
public $output = '';
protected function _write($message) {
$this->output .= $message;
}
}
class CommandListShellTest extends CakeTestCase {
/**
* setUp method
*
@ -85,7 +88,6 @@ class CommandListShellTest extends CakeTestCase {
$expected = "/welcome \[.*TestPluginTwo.*\]/";
$this->assertRegExp($expected, $output);
$expected = "/acl \[.*CORE.*\]/";
$this->assertRegExp($expected, $output);

View file

@ -38,9 +38,13 @@ if (!$imported) {
define('ARTICLE_MODEL_CREATED', true);
class BakeArticle extends Model {
public $name = 'BakeArticle';
public $hasMany = array('BakeComment');
public $hasAndBelongsToMany = array('BakeTag');
}
}
@ -303,7 +307,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->plugin = 'ControllerTest';
//fake plugin path
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
$this->Task->expects($this->at(1))->method('createFile')->with(
@ -551,7 +555,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
static function nameVariations() {
public static function nameVariations() {
return array(
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
);

View file

@ -110,7 +110,7 @@ class ExtractTaskTest extends CakeTestCase {
$pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Rename config\/database.php.default to ';
$pattern .= 'config\/database.php"\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
@ -358,7 +358,6 @@ class ExtractTaskTest extends CakeTestCase {
$this->assertRegExp($pattern, $result);
}
/**
* Test that the extract shell can obtain validation messages from models inside a specific plugin
*
@ -382,10 +381,10 @@ class ExtractTaskTest extends CakeTestCase {
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'test_plugin.pot');
$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field title#', '\\');
$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field title#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field body#', '\\');
$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field body#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post title is required"#';

View file

@ -377,7 +377,7 @@ class FixtureTaskTest extends CakeTestCase {
$filename = APP . 'Plugin' . DS . 'TestFixture' . DS . 'Test' . DS . 'Fixture' . DS . 'ArticleFixture.php';
//fake plugin path
CakePlugin::load('TestFixture', array('path' => APP . 'Plugin' . DS . 'TestFixture' . DS));
CakePlugin::load('TestFixture', array('path' => APP . 'Plugin' . DS . 'TestFixture' . DS));
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('class Article'));

View file

@ -823,7 +823,7 @@ STRINGEND;
$this->Task->plugin = 'ControllerTest';
//fake plugin path
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Model' . DS . 'BakeArticle.php';
$this->Task->expects($this->once())->method('createFile')
->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));
@ -861,7 +861,7 @@ STRINGEND;
*
* @return void
*/
static function nameVariations() {
public static function nameVariations() {
return array(
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
);

View file

@ -72,7 +72,7 @@ class PluginTaskTest extends CakeTestCase {
$path = $this->Task->path . 'BakeTestPlugin';
$file = $path . DS . 'Controller' . DS .'BakeTestPluginAppController.php';
$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());

View file

@ -93,11 +93,11 @@ class ProjectTaskTest extends CakeTestCase {
'Console' . DS . 'Templates',
'Console' . DS . 'Command' . DS . 'Task',
'Controller',
'Controller' . DS. 'Component',
'Controller' . DS . 'Component',
'Locale',
'Model',
'Model' . DS. 'Behavior',
'Model' . DS. 'Datasource',
'Model' . DS . 'Behavior',
'Model' . DS . 'Datasource',
'Plugin',
'Test',
'Test' . DS . 'Case',
@ -141,10 +141,10 @@ class ProjectTaskTest extends CakeTestCase {
$this->Task->execute();
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
$File = new File($path . DS . 'webroot' . DS . 'index.php');
$File = new File($path . DS . 'webroot' . DS . 'index.php');
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
$File = new File($path . DS . 'webroot' . DS . 'test.php');
$File = new File($path . DS . 'webroot' . DS . 'test.php');
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
}
@ -167,10 +167,10 @@ class ProjectTaskTest extends CakeTestCase {
$this->Task->execute();
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
$contents = file_get_contents($path . DS . 'webroot' . DS . 'index.php');
$contents = file_get_contents($path . DS . 'webroot' . DS . 'index.php');
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
$contents = file_get_contents($path . DS . 'webroot' . DS . 'test.php');
$contents = file_get_contents($path . DS . 'webroot' . DS . 'test.php');
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
ini_set('include_path', $restore);
@ -341,7 +341,7 @@ class ProjectTaskTest extends CakeTestCase {
$this->Task->execute();
$this->assertTrue(is_dir($path), 'No project dir');
$this->assertTrue(is_dir($path . DS . 'Controller'), 'No controllers dir ');
$this->assertTrue(is_dir($path . DS . 'Controller' . DS .'Component'), 'No components dir ');
$this->assertTrue(is_dir($path . DS . 'Controller' . DS . 'Component'), 'No components dir ');
$this->assertTrue(is_dir($path . DS . 'Model'), 'No models dir');
$this->assertTrue(is_dir($path . DS . 'View'), 'No views dir');
$this->assertTrue(is_dir($path . DS . 'View' . DS . 'Helper'), 'No helpers dir');

View file

@ -99,7 +99,7 @@ class TemplateTaskTest extends CakeTestCase {
* @return void
*/
public function testGetThemePath() {
$defaultTheme = CAKE . 'Console' . DS . 'Templates' . DS . 'default' .DS;
$defaultTheme = CAKE . 'Console' . DS . 'Templates' . DS . 'default' . DS;
$this->Task->templatePaths = array('default' => $defaultTheme);
$this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
@ -126,7 +126,7 @@ class TemplateTaskTest extends CakeTestCase {
public function testGenerate() {
App::build(array(
'Console' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS
)
));
$this->Task->initialize();
@ -146,7 +146,7 @@ class TemplateTaskTest extends CakeTestCase {
public function testGenerateWithTemplateFallbacks() {
App::build(array(
'Console' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS,
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS,
CAKE_CORE_INCLUDE_PATH . DS . 'console' . DS
)
));

View file

@ -99,6 +99,7 @@ class TestTaskArticle extends Model {
*/
protected function _innerMethod() {
}
}
/**
@ -403,7 +404,7 @@ class TestTaskTest extends CakeTestCase {
$result = $this->Task->getRealClassname('Controller', 'PostsController');
$this->assertEquals('PostsController', $result);
$result = $this->Task->getRealClassname('Controller', 'AlertTypes');
$this->assertEquals('AlertTypesController', $result);
@ -538,7 +539,6 @@ class TestTaskTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that mock class generation works for the appropriate classes
*
@ -558,8 +558,8 @@ class TestTaskTest extends CakeTestCase {
$this->Task->plugin = 'TestTest';
//fake plugin path
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS .'FormHelperTest.php';
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
$this->Task->expects($this->once())->method('createFile')
->with($path, $this->anything());
@ -636,10 +636,10 @@ class TestTaskTest extends CakeTestCase {
public function testTestCaseFileNamePlugin() {
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS ));
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS ));
$this->Task->plugin = 'TestTest';
$result = $this->Task->testCaseFileName('Model', 'Post');
$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
$this->assertEquals($expected, $result);
}

View file

@ -119,6 +119,7 @@ class ViewTaskCommentsController extends Controller {
*/
public function add() {
}
}
/**
@ -191,6 +192,7 @@ class ViewTaskArticlesController extends Controller {
*/
public function admin_delete() {
}
}
/**
@ -230,7 +232,7 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->path = TMP;
$this->Task->Template->params['theme'] = 'default';
$this->Task->Template->templatePaths = array('default' => CAKE . 'Console' . DS . 'Templates' . DS . 'default' .DS);
$this->Task->Template->templatePaths = array('default' => CAKE . 'Console' . DS . 'Templates' . DS . 'default' . DS);
}
/**
@ -384,8 +386,8 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->name = 'View';
//fake plugin path
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'View' . DS . 'ViewTaskComments' . DS . 'view.ctp';
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'View' . DS . 'ViewTaskComments' . DS . 'view.ctp';
$result = $this->Task->getContent('index');
$this->assertNotContains('List Test Test.view Task Articles', $result);
@ -607,7 +609,6 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('y', 'y', 'n'));
$this->Task->expects($this->at(3))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
@ -719,7 +720,7 @@ class ViewTaskTest extends CakeTestCase {
$this->assertEquals($result, 'form');
$this->Task->Template->templatePaths = array(
'test' => CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Templates' . DS . 'test' .DS
'test' => CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Templates' . DS . 'test' . DS
);
$this->Task->Template->params['theme'] = 'test';

View file

@ -29,11 +29,11 @@ class TestTestShell extends TestShell {
public function mapFileToCategory($file) {
return $this->_mapFileToCategory($file);
}
}
class TestShellTest extends CakeTestCase {
/**
* setUp test case
*
@ -111,7 +111,6 @@ class TestShellTest extends CakeTestCase {
$return = $this->Shell->mapFileToCategory(APP . 'My/File/Is/Here.php');
$this->assertSame('app', $return);
}
/**
@ -142,7 +141,6 @@ class TestShellTest extends CakeTestCase {
$return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php');
$this->assertSame('awesome', $return);
}
/**
@ -211,7 +209,6 @@ class TestShellTest extends CakeTestCase {
$return = $this->Shell->mapFileToCategory(APP . 'Test/Case/My/File/Is/HereTest.php');
$this->assertSame('app', $return);
}
/**
@ -242,7 +239,6 @@ class TestShellTest extends CakeTestCase {
$return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php');
$this->assertSame('awesome', $return);
}
/**

View file

@ -61,7 +61,6 @@ class TestShellDispatcher extends ShellDispatcher {
* @return void
*/
public function clear() {
}
/**
@ -96,6 +95,7 @@ class TestShellDispatcher extends ShellDispatcher {
}
return parent::_getShell($shell);
}
}
/**

View file

@ -55,20 +55,18 @@ class ShellTestShell extends Shell {
}
public function do_something() {
}
protected function _secret() {
}
protected function no_access() {
}
public function mergeVars($properties, $class, $normalize = true) {
return $this->_mergeVars($properties, $class, $normalize);
}
}
/**
@ -77,8 +75,11 @@ class ShellTestShell extends Shell {
* @package Cake.Test.Case.Console.Command
*/
class TestMergeShell extends Shell {
public $tasks = array('DbConfig', 'Fixture');
public $uses = array('Comment');
}
/**
@ -467,7 +468,7 @@ class ShellTest extends CakeTestCase {
*
* @return void
*/
public function test__getArgAndParamReferences() {
public function testMagicGetArgAndParamReferences() {
$this->Shell->tasks = array('TestApple');
$this->Shell->args = array('one');
$this->Shell->params = array('help' => false);
@ -489,7 +490,7 @@ class ShellTest extends CakeTestCase {
$path = $expected = DS . 'tmp' . DS . 'ab' . DS . 'cd';
$this->assertEquals($this->Shell->shortPath($path), $expected);
$path = $expected = DS . 'tmp' . DS . 'ab' . DS . 'cd' . DS ;
$path = $expected = DS . 'tmp' . DS . 'ab' . DS . 'cd' . DS;
$this->assertEquals($this->Shell->shortPath($path), $expected);
$path = $expected = DS . 'tmp' . DS . 'ab' . DS . 'index.php';
@ -566,7 +567,6 @@ class ShellTest extends CakeTestCase {
->method('read')
->will($this->returnValue('y'));
$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
@ -659,7 +659,6 @@ class ShellTest extends CakeTestCase {
->method('read')
->will($this->returnValue('y'));
$contents = "<?php\r\necho 'yet another test';\r\n\$te = 'st';\r\n";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
@ -774,7 +773,6 @@ class ShellTest extends CakeTestCase {
->will($this->returnValue($Parser));
$Mock->expects($this->once())->method('out');
$result = $Mock->runCommand('idontexist', array());
$this->assertFalse($result);
}
@ -866,7 +864,8 @@ TEXT;
$this->Shell->name = 'test';
$this->Shell->plugin = 'plugin';
$parser = $this->Shell->getOptionParser();
$this->assertEquals('plugin.test', $parser->command());
}
}

View file

@ -21,6 +21,7 @@ App::uses('TaskCollection', 'Console');
App::uses('Shell', 'Console');
class TaskCollectionTest extends CakeTestCase {
/**
* setUp
*