Skip to content

Commit

Permalink
Merge pull request #86 from vierge-noire/cake3_next
Browse files Browse the repository at this point in the history
 Issue #84 Add test to demonstrate association chain
  • Loading branch information
pabloelcolombiano authored May 21, 2021
2 parents f8b4bf7 + d869d06 commit 0afa9ab
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tmp/
composer.lock
**/test_fixture_factories
.phpunit.result.cache
.env
tests/.env

# These factories are baked by TestFixtureFactoryTaskTest
/tests/TestApp/tests/Factory/*
Expand Down
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ DRIVER=$1;
echo "Starting PHPUNIT tests"
export DB_DRIVER=$DRIVER

./vendor/bin/phpunit
./vendor/bin/phpunit
File renamed without changes.
File renamed without changes.
File renamed without changes.
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());
}
}
7 changes: 4 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@
putenv('DB_DRIVER=Sqlite');
}
$driver = getenv('DB_DRIVER');
$testDir = ROOT . DS . 'tests' . DS;

if (!file_exists(ROOT . DS . '.env')) {
@copy(".env.$driver", ROOT . DS . '.env');
if (!file_exists("$testDir.env")) {
@copy("$testDir.env.$driver", "$testDir.env");
}

/**
* Read .env file(s).
*/
$loadEnv(ROOT . DS . '.env');
$loadEnv("$testDir.env");

// Re-read the driver
$driver = getenv('DB_DRIVER');
Expand Down

0 comments on commit 0afa9ab

Please sign in to comment.