zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
611 stars 63 forks source link

Issues using PostGis #472

Closed KDederichs closed 1 year ago

KDederichs commented 1 year ago

Hey,

I'm running into this weird error when trying to tests while one entity has a geometry column type:

doctrine:schema:create [--em EM] [--dump-sql]

 in /srv/app/vendor/zenstruck/foundry/src/Test/AbstractSchemaResetter.php:33
Stack trace:
#0 /srv/app/vendor/zenstruck/foundry/src/Test/ORMDatabaseResetter.php(73): Zenstruck\Foundry\Test\AbstractSchemaResetter->runCommand(Object(Symfony\Bundle\FrameworkBundle\Console\Application), 'doctrine:schema...', Array)
#1 /srv/app/vendor/zenstruck/foundry/src/Test/ORMDatabaseResetter.php(50): Zenstruck\Foundry\Test\ORMDatabaseResetter->createSchema()
#2 /srv/app/vendor/zenstruck/foundry/src/Test/DatabaseResetter.php(48): Zenstruck\Foundry\Test\ORMDatabaseResetter->resetDatabase()
#3 /srv/app/vendor/zenstruck/foundry/src/Test/ResetDatabase.php(53): Zenstruck\Foundry\Test\DatabaseResetter::resetDatabase(Object(App\Kernel))
#4 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/src/Framework/TestSuite.php(619): App\Tests\Integration\Repository\ProfileRepositoryTest::_resetDatabase()
#5 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/src/Framework/TestSuite.php(675): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#6 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/src/Framework/TestSuite.php(675): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#7 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/src/TextUI/TestRunner.php(653): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#8 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/src/TextUI/Command.php(144): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true)
#9 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run(Array, true)
#10 /srv/app/vendor/bin/.phpunit/phpunit-9.5-0/phpunit(22): PHPUnit\TextUI\Command::main()
#11 /srv/app/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php(446): include('/srv/app/vendor...')
#12 /srv/app/bin/phpunit(18): require('/srv/app/vendor...')
#13 {main}
16) App\Tests\Integration\Repository\TriggerMessageRepositoryTest::testGetRandomNoUsed
RuntimeException: Error running "doctrine:schema:create": 
 ! [CAUTION] This operation should not be executed in a production environment!                                         

 Creating database schema...

In ToolsException.php line 19:

  Schema-Tool failed with Error 'An exception occurred while executing a query: SQLSTATE[42704]: Undefined object: 7 ERROR:  type "geometry" does not exist           
  LINE 1: ...LT NULL, city VARCHAR(255) DEFAULT NULL, geometry geometry(G...  

I'm not quite sure why it does this, since the Postgres DB has PostGis installed and enabled and the same entity works like that in normal dev mode.

I'm also running the dama/doctrine-test-bundle.

Anyone ever run into an issue like that or knows what might be up with it?

nikophil commented 1 year ago

Hi,

not sure this is totally related to Foundry.

how is your geometry type defined? if from a bundle, is this bundle enabled for test environment?

If you need further help, please, please create a reproducer app :pray:

KDederichs commented 1 year ago

Hi,

it's loaded through jsor/doctrine-postgis. And then just annotated with #[Column(type: PostGISType::GEOMETRY, nullable: true)].

There's no explicit bundles.php entry for it, it does hook into doctrine event subscribers for schema stuff though: https://github.com/jsor/doctrine-postgis/blob/main/docs/symfony.md

I can try and set up a producer if you like, probably gonna be tomorrow though since it's getting late here.

nikophil commented 1 year ago

Do you manage to persist entities with this geometry type, in test env, without foundry?

KDederichs commented 1 year ago

Sorry took a while. Seems like Foundry is not the issue as that error also occurs without it. Sorry for the inconvenience.