Browse Source

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
mark_story 11 years ago
parent
commit
3a18a0e92f
2 changed files with 30 additions and 4 deletions
  1. 8 2
      src/Shell/Task/TestTask.php
  2. 22 2
      tests/TestCase/Shell/Task/TestTaskTest.php

+ 8 - 2
src/Shell/Task/TestTask.php

@@ -335,9 +335,15 @@ class TestTask extends BakeTask {
 		$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();

+ 22 - 2
tests/TestCase/Shell/Task/TestTaskTest.php

@@ -27,6 +27,7 @@ use Cake\ORM\TableRegistry;
 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
@@ -226,6 +232,20 @@ class TestTaskTest extends TestCase {
  *
  * @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.
+ *
+ * @return void
+ */
 	public function testFixtureArrayGenerationFromController() {
 		$subject = new PostsController(new Request(), new Response());
 		$result = $this->Task->generateFixtureList($subject);