Skip to content

Commit

Permalink
Fix prefix paths for controller bake.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 21, 2014
1 parent 22b26d3 commit 92c89f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Console/Command/Task/ControllerTask.php
Expand Up @@ -191,6 +191,20 @@ public function bakeController($controllerName, $data) {
return $contents;
}

/**
* Gets the path for output. Checks the plugin property
* and returns the correct path.
*
* @return string Path to output.
*/
public function getPath() {
$path = parent::getPath();
if (!empty($this->params['prefix'])) {
$path .= Inflector::camelize($this->params['prefix']) . DS;
}
return $path;
}

/**
* Assembles and writes a unit test file
*
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Console/Command/Task/ControllerTaskTest.php
Expand Up @@ -66,6 +66,7 @@ public function setUp() {
);
$this->Task->name = 'Controller';
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';

$this->Task->Template = new TemplateTask($out, $out, $in);
$this->Task->Template->params['theme'] = 'default';
Expand Down Expand Up @@ -177,7 +178,15 @@ public function testBakeActions() {
$this->Task->params['helpers'] = 'Html,Time';
$this->Task->params['components'] = 'Csrf, Auth';

$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->at(1))
->method('createFile')
->with(
$filename,
$this->stringContains('class BakeArticlesController')
);
$result = $this->Task->bake('BakeArticles');

$this->assertTextContains('public function add(', $result);
$this->assertTextContains('public function index(', $result);
$this->assertTextContains('public function view(', $result);
Expand All @@ -193,7 +202,12 @@ public function testBakeActions() {
public function testBakePrefixed() {
$this->Task->params['prefix'] = 'Admin';

$filename = '/my/path/Admin/BakeArticlesController.php';
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->anything());
$result = $this->Task->bake('BakeArticles');

$this->assertTextContains('namespace App\Controller\Admin;', $result);
$this->assertTextContains('use App\Controller\AppController;', $result);
}
Expand Down

0 comments on commit 92c89f7

Please sign in to comment.