diff --git a/.gitignore b/.gitignore index 663eebe8..561c3025 100644 --- a/.gitignore +++ b/.gitignore @@ -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/* diff --git a/run_tests.sh b/run_tests.sh index bf3d1668..097311f0 100644 --- a/run_tests.sh +++ b/run_tests.sh @@ -5,4 +5,4 @@ DRIVER=$1; echo "Starting PHPUNIT tests" export DB_DRIVER=$DRIVER -./vendor/bin/phpunit \ No newline at end of file +./vendor/bin/phpunit diff --git a/.env.Mysql b/tests/.env.Mysql similarity index 100% rename from .env.Mysql rename to tests/.env.Mysql diff --git a/.env.Postgres b/tests/.env.Postgres similarity index 100% rename from .env.Postgres rename to tests/.env.Postgres diff --git a/.env.Sqlite b/tests/.env.Sqlite similarity index 100% rename from .env.Sqlite rename to tests/.env.Sqlite diff --git a/tests/TestCase/Factory/BaseFactoryAssociationsTest.php b/tests/TestCase/Factory/BaseFactoryAssociationsTest.php index 440c5042..5375559a 100644 --- a/tests/TestCase/Factory/BaseFactoryAssociationsTest.php +++ b/tests/TestCase/Factory/BaseFactoryAssociationsTest.php @@ -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()); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0033b8a8..3e65828c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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');