Skip to content

Commit

Permalink
Issue #84 Add test to demonstrate association chain
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloelcolombiano committed May 21, 2021
1 parent 4628554 commit d869d06
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/TestCase/Factory/BaseFactoryAssociationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,28 @@ public function testAssociationWithVirtualFieldNamedIdentically()
$this->assertSame(1, $this->CitiesTable->find()->count());
$this->assertSame(1, $this->CountriesTable->find()->count());
}

/**
* Reproduce the issue reported here: https://github.com/vierge-noire/cakephp-fixture-factories/issues/84
*/
public function testReproduceIssue84()
{
$articles = ArticleFactory::make(2)
->with('Authors[5]', ['biography' => 'Foo'])
->with('Bills')
->persist();

$this->assertSame(2, count($articles));
foreach ($articles as $article) {
$this->assertSame(5, count($article->authors));
foreach ($article->authors as $author) {
$this->assertSame('Foo', $author->biography);
}
$this->assertSame(1, count($article->bills));
}

$this->assertSame(2, $this->ArticlesTable->find()->count());
$this->assertSame(10, $this->AuthorsTable->find()->count());
$this->assertSame(2, $this->BillsTable->find()->count());
}
}

0 comments on commit d869d06

Please sign in to comment.