Skip to content
Permalink
Browse files

Fix fixture generation.

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 3a18a0e92f5c8117bd7bcb02a99c6d56ded1dfa6
Showing with 30 additions and 4 deletions.
  1. +8 −2 src/Shell/Task/TestTask.php
  2. +22 −2 tests/TestCase/Shell/Task/TestTaskTest.php
@@ -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();
@@ -27,6 +27,7 @@
use Cake\TestSuite\TestCase;
use TestApp\Controller\PostsController;
use TestApp\Model\Table\ArticlesTable;
use TestApp\Model\Table\CategoryThreadsTable;
/**
* TestTaskTest class
@@ -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
@@ -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.
*

0 comments on commit 3a18a0e

Please sign in to comment.
You can’t perform that action at this time.