Skip to content

Commit

Permalink
Merge pull request #56 from cakephp/all-tests
Browse files Browse the repository at this point in the history
Add ability to bake all tests for a given type
  • Loading branch information
jadb committed Mar 17, 2015
2 parents 0adfe6f + f0d794f commit 9bebeff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Shell/Task/TestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function main($type = null, $name = null)
return $this->outputTypeChoices();
}

if ($this->param('all')) {
return $this->_bakeAll($type);
}

if (empty($name)) {
return $this->outputClassChoices($type);
}
Expand Down Expand Up @@ -146,6 +150,26 @@ public function outputClassChoices($type)
return $options;
}

/**
* @param string $type The typename to get bake all classes for.
* @return void
*/
protected function _bakeAll($type)
{
$mappedType = $this->mapType($type);
$classes = $this->_getClassOptions($mappedType);

foreach ($classes as $class) {
if ($this->bake($type, $class)) {
$this->out('<success>Done - ' . $class . '</success>');
} else {
$this->out('<error>Failed - ' . $class . '</error>');
}
}

$this->out('<info>Bake finished</info>');
}

/**
* Get the possible classes for a given type.
*
Expand Down Expand Up @@ -572,6 +596,9 @@ public function getOptionParser()
'help' => 'An existing class to bake tests for.'
])->addOption('fixtures', [
'help' => 'A comma separated list of fixture names you want to include.'
])->addOption('all', [
'boolean' => true,
'help' => 'Bake all classes of the given type'
]);

return $parser;
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/Shell/Task/TestTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ public function testExecuteWithTwoArgs()
$this->Task->main('Table', 'TestTaskTag');
}

/**
* test execute with type and class name defined
*
* @return void
*/
public function testExecuteWithAll()
{
$this->Task->expects($this->exactly(2))->method('createFile')
->withConsecutive(
[
$this->stringContains('TestCase' . DS . 'Model' . DS . 'Table' . DS . 'ArticlesTableTest.php'),
$this->stringContains('class ArticlesTableTest extends TestCase')
],
[
$this->stringContains('TestCase' . DS . 'Model' . DS . 'Table' . DS . 'CategoryThreadsTableTest.php'),
$this->stringContains('class CategoryThreadsTableTest extends TestCase')
]
);
$this->Task->params['all'] = true;
$this->Task->main('Table');
}

/**
* Test generating class options for table.
*
Expand Down

0 comments on commit 9bebeff

Please sign in to comment.