From ed1d34accc395ec476ad9822bc90c1b1126b99cd Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 10 Mar 2012 23:32:02 -0500 Subject: [PATCH] Fix most coding standards issues in Test/Console --- .../Test/Case/Console/Command/BakeShellTest.php | 6 ++++-- .../Console/Command/CommandListShellTest.php | 4 +++- .../Console/Command/Task/ControllerTaskTest.php | 8 ++++++-- .../Console/Command/Task/ExtractTaskTest.php | 7 +++---- .../Console/Command/Task/FixtureTaskTest.php | 2 +- .../Case/Console/Command/Task/ModelTaskTest.php | 4 ++-- .../Console/Command/Task/PluginTaskTest.php | 2 +- .../Console/Command/Task/ProjectTaskTest.php | 16 ++++++++-------- .../Console/Command/Task/TemplateTaskTest.php | 6 +++--- .../Case/Console/Command/Task/TestTaskTest.php | 12 ++++++------ .../Case/Console/Command/Task/ViewTaskTest.php | 11 ++++++----- .../Test/Case/Console/Command/TestShellTest.php | 6 +----- .../Test/Case/Console/ShellDispatcherTest.php | 2 +- lib/Cake/Test/Case/Console/ShellTest.php | 17 ++++++++--------- .../Test/Case/Console/TaskCollectionTest.php | 1 + 15 files changed, 54 insertions(+), 50 deletions(-) diff --git a/lib/Cake/Test/Case/Console/Command/BakeShellTest.php b/lib/Cake/Test/Case/Console/Command/BakeShellTest.php index 0bac5fa9c1a..caeb24d6b3c 100644 --- a/lib/Cake/Test/Case/Console/Command/BakeShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/BakeShellTest.php @@ -28,7 +28,9 @@ if (!class_exists('UsersController')) { class UsersController extends Controller { + public $name = 'Users'; + } } @@ -89,7 +91,7 @@ public function testAllWithModelName() { $this->Shell->Model->expects($this->never()) ->method('getName'); - + $this->Shell->Model->expects($this->once()) ->method('bake') ->will($this->returnValue(true)); @@ -97,7 +99,7 @@ public function testAllWithModelName() { $this->Shell->Controller->expects($this->once()) ->method('bake') ->will($this->returnValue(true)); - + $this->Shell->View->expects($this->once()) ->method('execute'); diff --git a/lib/Cake/Test/Case/Console/Command/CommandListShellTest.php b/lib/Cake/Test/Case/Console/Command/CommandListShellTest.php index 71e9ae96cf1..994b6dda250 100644 --- a/lib/Cake/Test/Case/Console/Command/CommandListShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/CommandListShellTest.php @@ -24,14 +24,17 @@ class TestStringOutput extends ConsoleOutput { + public $output = ''; protected function _write($message) { $this->output .= $message; } + } class CommandListShellTest extends CakeTestCase { + /** * setUp method * @@ -85,7 +88,6 @@ public function testMain() { $expected = "/welcome \[.*TestPluginTwo.*\]/"; $this->assertRegExp($expected, $output); - $expected = "/acl \[.*CORE.*\]/"; $this->assertRegExp($expected, $output); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php index 7b37154d122..27b51359752 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php @@ -38,9 +38,13 @@ define('ARTICLE_MODEL_CREATED', true); class BakeArticle extends Model { + public $name = 'BakeArticle'; + public $hasMany = array('BakeComment'); + public $hasAndBelongsToMany = array('BakeTag'); + } } @@ -303,7 +307,7 @@ public function testBakeWithPlugin() { $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 @@ public function testExecuteWithController() { * * @return void */ - static function nameVariations() { + public static function nameVariations() { return array( array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles') ); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php index fc445b3773c..ff6e563623f 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php @@ -110,7 +110,7 @@ public function testExecute() { $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 @@ public function testExtractModelValidationWithDomainInModel() { $this->assertRegExp($pattern, $result); } - /** * Test that the extract shell can obtain validation messages from models inside a specific plugin * @@ -382,10 +381,10 @@ public function testExtractModelValidationInPlugin() { $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"#'; diff --git a/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php index 197c79afe97..5e164539c2c 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php @@ -377,7 +377,7 @@ public function testGeneratePluginFixtureFile() { $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')); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index 46a6b677e2d..7154307e764 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -823,7 +823,7 @@ public function testBakeWithPlugin() { $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 @@ public function testExecuteWithNamedModel() { * * @return void */ - static function nameVariations() { + public static function nameVariations() { return array( array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles') ); diff --git a/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php index 68fc003f2bf..faa3e18e8a5 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php @@ -72,7 +72,7 @@ public function testBakeFoldersAndFiles() { $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()); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php index dbc4a08c418..f36368d95e8 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php @@ -93,11 +93,11 @@ public function testBake() { '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 @@ public function testExecuteWithAbsolutePath() { $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 @@ public function testExecuteWithCakeOnIncludePath() { $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 @@ public function testExecute() { $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'); diff --git a/lib/Cake/Test/Case/Console/Command/Task/TemplateTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/TemplateTaskTest.php index 2a0eeb73c39..e2ce61a98fe 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/TemplateTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/TemplateTaskTest.php @@ -99,7 +99,7 @@ public function testFindingInstalledThemesForBake() { * @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 @@ public function testGetThemePath() { 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 @@ public function testGenerate() { 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 ) )); diff --git a/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php index aaf62b8c3ef..67092023a4a 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php @@ -99,6 +99,7 @@ public function doSomethingElse() { */ protected function _innerMethod() { } + } /** @@ -403,7 +404,7 @@ public function testGetRealClassname() { $result = $this->Task->getRealClassname('Controller', 'PostsController'); $this->assertEquals('PostsController', $result); - + $result = $this->Task->getRealClassname('Controller', 'AlertTypes'); $this->assertEquals('AlertTypesController', $result); @@ -538,7 +539,6 @@ public function testGenerateUses() { $this->assertEquals($expected, $result); } - /** * Test that mock class generation works for the appropriate classes * @@ -558,8 +558,8 @@ public function testBakeWithPlugin() { $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 @@ public function testTestCaseFileName($type, $class, $expected) { 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); } diff --git a/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php index 6412854fb9d..8ca4b99ce50 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php @@ -119,6 +119,7 @@ public function index() { */ public function add() { } + } /** @@ -191,6 +192,7 @@ public function admin_edit() { */ public function admin_delete() { } + } /** @@ -230,7 +232,7 @@ public function setUp() { $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 @@ public function testBakeWithPlugin() { $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 @@ public function testExecuteInteractive() { $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 @@ public function testGetTemplate() { $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'; diff --git a/lib/Cake/Test/Case/Console/Command/TestShellTest.php b/lib/Cake/Test/Case/Console/Command/TestShellTest.php index b787d40532f..2440647ab65 100644 --- a/lib/Cake/Test/Case/Console/Command/TestShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/TestShellTest.php @@ -29,11 +29,11 @@ public function mapFileToCase($file, $category, $throwOnMissingFile = true) { public function mapFileToCategory($file) { return $this->_mapFileToCategory($file); } + } class TestShellTest extends CakeTestCase { - /** * setUp test case * @@ -111,7 +111,6 @@ public function testMapAppFileToCategory() { $return = $this->Shell->mapFileToCategory(APP . 'My/File/Is/Here.php'); $this->assertSame('app', $return); - } /** @@ -142,7 +141,6 @@ public function testMapPluginFileToCategory() { $return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php'); $this->assertSame('awesome', $return); - } /** @@ -211,7 +209,6 @@ public function testMapAppTestToCategory() { $return = $this->Shell->mapFileToCategory(APP . 'Test/Case/My/File/Is/HereTest.php'); $this->assertSame('app', $return); - } /** @@ -242,7 +239,6 @@ public function testMapPluginTestToCategory() { $return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php'); $this->assertSame('awesome', $return); - } /** diff --git a/lib/Cake/Test/Case/Console/ShellDispatcherTest.php b/lib/Cake/Test/Case/Console/ShellDispatcherTest.php index 1d6082dca9b..fd48a84d218 100644 --- a/lib/Cake/Test/Case/Console/ShellDispatcherTest.php +++ b/lib/Cake/Test/Case/Console/ShellDispatcherTest.php @@ -61,7 +61,6 @@ protected function _initEnvironment() { * @return void */ public function clear() { - } /** @@ -96,6 +95,7 @@ protected function _getShell($shell) { } return parent::_getShell($shell); } + } /** diff --git a/lib/Cake/Test/Case/Console/ShellTest.php b/lib/Cake/Test/Case/Console/ShellTest.php index 2cfced3f902..732b0588e67 100644 --- a/lib/Cake/Test/Case/Console/ShellTest.php +++ b/lib/Cake/Test/Case/Console/ShellTest.php @@ -55,20 +55,18 @@ protected function _stop($status = 0) { } 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 @@ public function mergeVars($properties, $class, $normalize = true) { * @package Cake.Test.Case.Console.Command */ class TestMergeShell extends Shell { + public $tasks = array('DbConfig', 'Fixture'); + public $uses = array('Comment'); + } /** @@ -467,7 +468,7 @@ public function testLoadTasks() { * * @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 @@ public function testShortPath() { $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 @@ public function testCreateFileInteractive() { ->method('read') ->will($this->returnValue('y')); - $contents = "Shell->createFile($file, $contents); $this->assertTrue($result); @@ -659,7 +659,6 @@ public function testCreateFileWindowsInteractive() { ->method('read') ->will($this->returnValue('y')); - $contents = "Shell->createFile($file, $contents); $this->assertTrue($result); @@ -774,7 +773,6 @@ public function testRunCommandMissingMethod() { ->will($this->returnValue($Parser)); $Mock->expects($this->once())->method('out'); - $result = $Mock->runCommand('idontexist', array()); $this->assertFalse($result); } @@ -866,7 +864,8 @@ public function testGetOptionParser() { $this->Shell->name = 'test'; $this->Shell->plugin = 'plugin'; $parser = $this->Shell->getOptionParser(); - + $this->assertEquals('plugin.test', $parser->command()); } + } diff --git a/lib/Cake/Test/Case/Console/TaskCollectionTest.php b/lib/Cake/Test/Case/Console/TaskCollectionTest.php index e3cbcf173f2..19540813f37 100644 --- a/lib/Cake/Test/Case/Console/TaskCollectionTest.php +++ b/lib/Cake/Test/Case/Console/TaskCollectionTest.php @@ -21,6 +21,7 @@ App::uses('Shell', 'Console'); class TaskCollectionTest extends CakeTestCase { + /** * setUp *