Skip to content

Commit

Permalink
Fix most coding standards issues in Test/Console
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 11, 2012
1 parent fdcb3dc commit ed1d34a
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 50 deletions.
6 changes: 4 additions & 2 deletions lib/Cake/Test/Case/Console/Command/BakeShellTest.php
Expand Up @@ -28,7 +28,9 @@

if (!class_exists('UsersController')) {
class UsersController extends Controller {

public $name = 'Users';

}
}

Expand Down Expand Up @@ -89,15 +91,15 @@ public function testAllWithModelName() {

$this->Shell->Model->expects($this->never())
->method('getName');

$this->Shell->Model->expects($this->once())
->method('bake')
->will($this->returnValue(true));

$this->Shell->Controller->expects($this->once())
->method('bake')
->will($this->returnValue(true));

$this->Shell->View->expects($this->once())
->method('execute');

Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Test/Case/Console/Command/CommandListShellTest.php
Expand Up @@ -24,14 +24,17 @@


class TestStringOutput extends ConsoleOutput {

public $output = '';

protected function _write($message) {
$this->output .= $message;
}

}

class CommandListShellTest extends CakeTestCase {

/**
* setUp method
*
Expand Down Expand Up @@ -85,7 +88,6 @@ public function testMain() {
$expected = "/welcome \[.*TestPluginTwo.*\]/";
$this->assertRegExp($expected, $output);


$expected = "/acl \[.*CORE.*\]/";
$this->assertRegExp($expected, $output);

Expand Down
Expand Up @@ -38,9 +38,13 @@
define('ARTICLE_MODEL_CREATED', true);

class BakeArticle extends Model {

public $name = 'BakeArticle';

public $hasMany = array('BakeComment');

public $hasAndBelongsToMany = array('BakeTag');

}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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')
);
Expand Down
7 changes: 3 additions & 4 deletions lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand All @@ -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"#';
Expand Down
Expand Up @@ -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'));

Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -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'));
Expand Down Expand Up @@ -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')
);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php
Expand Up @@ -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());

Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Console/Command/Task/TemplateTaskTest.php
Expand Up @@ -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'));
Expand All @@ -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();
Expand All @@ -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
)
));
Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php
Expand Up @@ -99,6 +99,7 @@ public function doSomethingElse() {
*/
protected function _innerMethod() {
}

}

/**
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -538,7 +539,6 @@ public function testGenerateUses() {
$this->assertEquals($expected, $result);
}


/**
* Test that mock class generation works for the appropriate classes
*
Expand All @@ -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());

Expand Down Expand Up @@ -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);
}

Expand Down
11 changes: 6 additions & 5 deletions lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php
Expand Up @@ -119,6 +119,7 @@ public function index() {
*/
public function add() {
}

}

/**
Expand Down Expand Up @@ -191,6 +192,7 @@ public function admin_edit() {
*/
public function admin_delete() {
}

}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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';

Expand Down
6 changes: 1 addition & 5 deletions lib/Cake/Test/Case/Console/Command/TestShellTest.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -111,7 +111,6 @@ public function testMapAppFileToCategory() {

$return = $this->Shell->mapFileToCategory(APP . 'My/File/Is/Here.php');
$this->assertSame('app', $return);

}

/**
Expand Down Expand Up @@ -142,7 +141,6 @@ public function testMapPluginFileToCategory() {

$return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php');
$this->assertSame('awesome', $return);

}

/**
Expand Down Expand Up @@ -211,7 +209,6 @@ public function testMapAppTestToCategory() {

$return = $this->Shell->mapFileToCategory(APP . 'Test/Case/My/File/Is/HereTest.php');
$this->assertSame('app', $return);

}

/**
Expand Down Expand Up @@ -242,7 +239,6 @@ public function testMapPluginTestToCategory() {

$return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php');
$this->assertSame('awesome', $return);

}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Console/ShellDispatcherTest.php
Expand Up @@ -61,7 +61,6 @@ protected function _initEnvironment() {
* @return void
*/
public function clear() {

}

/**
Expand Down Expand Up @@ -96,6 +95,7 @@ protected function _getShell($shell) {
}
return parent::_getShell($shell);
}

}

/**
Expand Down

0 comments on commit ed1d34a

Please sign in to comment.