Skip to content

Commit

Permalink
Fix fixture generation.
Browse files Browse the repository at this point in the history
When generating fixtures don't add fixtures for self associated models.
Generally all instances of one class will use the same fixture and
including additional fixtures for aliases will only cause problems.

Refs #4440
  • Loading branch information
markstory committed Sep 1, 2014
1 parent ae7d610 commit 3a18a0e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Shell/Task/TestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,15 @@ protected function _processModel($subject) {
$this->_addFixture($subject->alias());
foreach ($subject->associations()->keys() as $alias) {
$assoc = $subject->association($alias);
$name = $assoc->target()->alias();
$target = $assoc->target();
$name = $target->alias();

if (get_class($subject) === get_class($target)) {
continue;
}

if (!isset($this->_fixtures[$name])) {
$this->_processModel($assoc->target());
$this->_processModel($target);
}
if ($assoc->type() === Association::MANY_TO_MANY) {
$junction = $assoc->junction();
Expand Down
24 changes: 22 additions & 2 deletions tests/TestCase/Shell/Task/TestTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Cake\TestSuite\TestCase;
use TestApp\Controller\PostsController;
use TestApp\Model\Table\ArticlesTable;
use TestApp\Model\Table\CategoryThreadsTable;

/**
* TestTaskTest class
Expand All @@ -39,8 +40,13 @@ class TestTaskTest extends TestCase {
*
* @var string
*/
public $fixtures = ['core.article', 'core.author',
'core.comment', 'core.articles_tag', 'core.tag'];
public $fixtures = [
'core.article',
'core.author',
'core.comment',
'core.articles_tag',
'core.tag',
];

/**
* setUp method
Expand Down Expand Up @@ -221,6 +227,20 @@ public function testFixtureArrayGenerationFromModel() {
$this->assertEquals($expected, $result);
}

/**
* test that the generation of fixtures works correctly.
*
* @return void
*/
public function testFixtureArrayGenerationIgnoreSelfAssociation() {
$subject = new CategoryThreadsTable();
$result = $this->Task->generateFixtureList($subject);
$expected = [
'app.category_thread',
];
$this->assertEquals($expected, $result);
}

/**
* test that the generation of fixtures works correctly.
*
Expand Down

0 comments on commit 3a18a0e

Please sign in to comment.