Skip to content

Commit

Permalink
Merge pull request #149 from cakephp/phinxlog
Browse files Browse the repository at this point in the history
fix `bake controller all` and `bake template all`
  • Loading branch information
markstory committed Aug 15, 2015
2 parents 8bed054 + 5cc5d0d commit bac96a3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0

sudo: false

Expand All @@ -19,7 +20,7 @@ matrix:
fast_finish: true

include:
- php: 5.4
- php: 7.0
env: RUN_CS=1 RUN_TESTS=0

- php: 5.4
Expand Down
5 changes: 3 additions & 2 deletions src/Shell/Task/ControllerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function main($name = null)
*/
public function all()
{
foreach ($this->listAll() as $table) {
$tables = $this->listAll();
foreach ($tables as $table) {
TableRegistry::clear();
$this->main($table);
}
Expand Down Expand Up @@ -243,7 +244,7 @@ public function getHelpers()
public function listAll()
{
$this->Model->connection = $this->connection;
return $this->Model->listAll();
return $this->Model->listUnskipped();
}

/**
Expand Down
22 changes: 15 additions & 7 deletions src/Shell/Task/ModelTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ModelTask extends BakeTask
*
* @var array
*/
public $skipTables = ['i18n'];
public $skipTables = ['i18n', 'phinxlog'];

/**
* Holds tables found on connection.
Expand Down Expand Up @@ -142,11 +142,8 @@ public function bake($name)
*/
public function all()
{
$this->listAll($this->connection, false);
foreach ($this->_tables as $table) {
if (in_array($table, $this->skipTables)) {
continue;
}
$tables = $this->listUnskipped();
foreach ($tables as $table) {
TableRegistry::clear();
$this->main($table);
}
Expand Down Expand Up @@ -292,7 +289,7 @@ public function findBelongsTo($model, array $associations)
public function findTableReferencedBy($schema, $keyField)
{
if (!$schema->column($keyField)) {
return null;
return null;
}
foreach ($schema->constraints() as $constraint) {
$constraintInfo = $schema->constraint($constraint);
Expand Down Expand Up @@ -799,6 +796,17 @@ public function listAll()
return $this->_tables;
}

/**
* Outputs the a list of unskipped models or controllers from database
*
* @return array
*/
public function listUnskipped()
{
$this->listAll();
return array_diff($this->_tables, $this->skipTables);
}

/**
* Get an Array of all the tables in the supplied connection
* will halt the script if no tables are found.
Expand Down
2 changes: 1 addition & 1 deletion src/Shell/Task/TemplateTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected function _methodsToBake()
public function all()
{
$this->Model->connection = $this->connection;
$tables = $this->Model->listAll();
$tables = $this->Model->listUnskipped();

foreach ($tables as $table) {
$this->main($table);
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/Shell/Task/ControllerTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ public function testListAll()
$this->assertContains('bake_tags', $result);
}

/**
* test ListAll
*
* @return void
*/
public function testListAllWithSkippedTable()
{
$this->Task->Model->skipTables = ['bake_articles', 'bake_comments'];
$result = $this->Task->listAll();
$this->assertNotContains('bake_articles', $result);
$this->assertNotContains('bake_comments', $result);
$this->assertContains('bake_articles_bake_tags', $result);
$this->assertContains('bake_tags', $result);
}

/**
* test component generation
*
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/Task/TemplateTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public function testAllCallsMain()
$this->_setupTask(['in', 'err', 'createFile', 'main', '_stop']);

$this->Task->Model->expects($this->once())
->method('listAll')
->method('listUnskipped')
->will($this->returnValue(['comments', 'articles']));

$this->Task->expects($this->exactly(2))
Expand Down

0 comments on commit bac96a3

Please sign in to comment.