Skip to content

Commit

Permalink
Merge pull request #261 from cakephp/new-cs-rule
Browse files Browse the repository at this point in the history
Remove deprecated getMock in tests and generated code + new cs rule
  • Loading branch information
antograssiot authored Jul 14, 2016
2 parents 0afd98e + c26e93e commit 9aa0f6f
Show file tree
Hide file tree
Showing 44 changed files with 334 additions and 168 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"cakephp/cakephp": ">=3.2.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "dev-master",
"cakephp/cakephp-codesniffer": "^2.1",
"phpunit/phpunit": "*"
},
"autoload": {
Expand Down
8 changes: 8 additions & 0 deletions src/Shell/BakeShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ public function main()
array_shift($args);
$args = implode($args, ' ');
$this->out(sprintf(' <info>`bin/cake bake template %s`</info>', $args), 2);

return false;
}

$connections = ConnectionManager::configured();
if (empty($connections)) {
$this->out('Your database configuration was not found.');
$this->out('Add your database connection information to config/app.php.');

return false;
}
$this->out('The following commands can be used to generate skeleton code for your application.', 2);
Expand All @@ -102,6 +104,7 @@ public function main()
}
$this->out('');
$this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');

return false;
}

Expand Down Expand Up @@ -158,6 +161,7 @@ protected function _findTasks($tasks, $path, $namespace, $prefix = null)
$fullName = ($prefix ? $prefix . '.' : '') . $name;
$tasks[$name] = $fullName;
}

return $tasks;
}

Expand All @@ -179,6 +183,7 @@ protected function _findClassFiles($path, $namespace)
$name = $item->getBasename('.php');
$candidates[] = $namespace . '\Shell\Task\\' . $name;
}

return $candidates;
}

Expand All @@ -204,6 +209,7 @@ protected function _findTaskClasses($files)
}
$classes[] = $className;
}

return $classes;
}

Expand All @@ -229,6 +235,7 @@ public function all($name = null)
$this->out('- ' . $table);
}
$this->out('Run <info>`cake bake all [name]`</info> to generate skeleton files.');

return false;
}

Expand All @@ -253,6 +260,7 @@ public function all($name = null)
});

$this->out('<success>Bake All complete.</success>', 1, Shell::QUIET);

return true;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Shell/Task/BakeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected function _getPrefix()
return '';
}
$parts = explode('/', $prefix);

return implode('/', array_map([$this, '_camelize'], $parts));
}

Expand All @@ -109,6 +110,7 @@ public function getPath()
if ($prefix) {
$path .= $prefix . DS;
}

return str_replace('/', DS, $path);
}

Expand All @@ -124,6 +126,7 @@ public function main()
$this->plugin = $this->params['plugin'];
if (strpos($this->plugin, '\\')) {
$this->abort('Invalid plugin namespace separator, please use / instead of \ for plugins.');

return;
}
}
Expand Down Expand Up @@ -154,6 +157,7 @@ public function callProcess($command)
);
if (!is_resource($process)) {
$this->abort('Could not start subprocess.');

return;
}
fclose($pipes[0]);
Expand Down Expand Up @@ -186,6 +190,7 @@ protected function _getName($name)
list($plugin, $name) = pluginSplit($name);
$this->plugin = $this->params['plugin'] = $plugin;
}

return $name;
}

Expand Down
1 change: 1 addition & 0 deletions src/Shell/Task/BakeTemplateTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function generate($template, $vars = null)
return $this->View->render($template);
} catch (MissingTemplateException $e) {
$this->_io->verbose(sprintf('No bake template found for "%s"', $template));

return '';
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Shell/Task/CellTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ public function template()
* Bake the Cell class and template file.
*
* @param string $name The name of the cell to make.
* @return void
* @return string
*/
public function bake($name)
{
$this->bakeTemplate($name);

return parent::bake($name);
}

Expand Down
11 changes: 9 additions & 2 deletions src/Shell/Task/ControllerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ControllerTask extends BakeTask
* Execution method always used for tasks
*
* @param string|null $name The name of the controller to bake.
* @return void
* @return null|bool
*/
public function main($name = null)
{
Expand All @@ -58,6 +58,7 @@ public function main($name = null)
foreach ($this->listAll() as $table) {
$this->out('- ' . $this->_camelize($table));
}

return true;
}

Expand Down Expand Up @@ -149,6 +150,7 @@ public function bake($controllerName)

$out = $this->bakeController($controllerName, $data);
$this->bakeTest($controllerName);

return $out;
}

Expand Down Expand Up @@ -179,14 +181,15 @@ public function bakeController($controllerName, array $data)
$path = $this->getPath();
$filename = $path . $controllerName . 'Controller.php';
$this->createFile($filename, $contents);

return $contents;
}

/**
* Assembles and writes a unit test file
*
* @param string $className Controller class name
* @return string Baked test
* @return void|string Baked test
*/
public function bakeTest($className)
{
Expand All @@ -199,6 +202,7 @@ public function bakeTest($className)
if ($prefix) {
$className = str_replace('/', '\\', $prefix) . '\\' . $className;
}

return $this->Test->bake('Controller', $className);
}

Expand All @@ -214,6 +218,7 @@ public function getComponents()
$components = explode(',', $this->params['components']);
$components = array_values(array_filter(array_map('trim', $components)));
}

return $components;
}

Expand All @@ -229,6 +234,7 @@ public function getHelpers()
$helpers = explode(',', $this->params['helpers']);
$helpers = array_values(array_filter(array_map('trim', $helpers)));
}

return $helpers;
}

Expand All @@ -240,6 +246,7 @@ public function getHelpers()
public function listAll()
{
$this->Model->connection = $this->connection;

return $this->Model->listUnskipped();
}

Expand Down
10 changes: 9 additions & 1 deletion src/Shell/Task/FixtureTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function getPath()
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests/' . $dir;
}

return str_replace('/', DS, $path);
}

Expand Down Expand Up @@ -97,7 +98,7 @@ public function getOptionParser()
* Handles dispatching to interactive, named, or all processes.
*
* @param string|null $name The name of the fixture to bake.
* @return void
* @return null|bool
*/
public function main($name = null)
{
Expand All @@ -109,6 +110,7 @@ public function main($name = null)
foreach ($this->Model->listUnskipped() as $table) {
$this->out('- ' . $this->_camelize($table));
}

return true;
}

Expand Down Expand Up @@ -193,6 +195,7 @@ public function bake($model, $useTable = null)
if (!empty($this->params['records'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}

return $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import'));
}

Expand Down Expand Up @@ -230,6 +233,7 @@ public function generateFixtureFile($model, array $otherVars)
$this->createFile($path . $filename, $content);
$emptyFile = $path . 'empty';
$this->_deleteEmptyFile($emptyFile);

return $content;
}

Expand Down Expand Up @@ -272,6 +276,7 @@ protected function _generateSchema(Table $table)
}
$content .= " '_options' => [\n" . implode(",\n", $options) . "\n ],\n";
}

return "[\n$content ]";
}

Expand Down Expand Up @@ -302,6 +307,7 @@ protected function _values($values)
}
}
}

return $vals;
}

Expand Down Expand Up @@ -373,6 +379,7 @@ protected function _generateRecords(Table $table, $recordCount = 1)
}
$records[] = $record;
}

return $records;
}

Expand Down Expand Up @@ -402,6 +409,7 @@ protected function _makeRecordString($records)
$out .= "\n ],\n";
}
$out .= " ]";

return $out;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Shell/Task/MailerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public function template()
* Bake the Mailer class and html/text layout files.
*
* @param string $name The name of the mailer to make.
* @return void
* @return string
*/
public function bake($name)
{
$this->bakeLayouts($name);

return parent::bake($name);
}

Expand Down
Loading

0 comments on commit 9aa0f6f

Please sign in to comment.