From 32570952398d5d8562a76e802e48e5a5705d8013 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Sun, 1 Sep 2024 18:01:01 +0200 Subject: [PATCH] refactor: extract reset:migration tests in another testsuite --- .env | 1 - .github/workflows/ci.yml | 70 ++++++++-- README.md | 26 ++-- bin/console | 4 +- composer.json | 19 +-- phpunit-10.xml.dist | 3 +- phpunit.xml.dist | 7 +- .../Version20240611065130.php | 44 ------ .../EntityInAnotherSchema/Article.php | 8 +- tests/Fixture/TestKernel.php | 17 +-- tests/Fixture/TestMigrationKernel.php | 125 ++++++++++++++++++ .../ResetDatabaseWithMigrationTest.php | 73 ++++++++++ tests/bootstrap-migrate.php | 44 ++++++ tests/bootstrap.php | 31 ----- 14 files changed, 340 insertions(+), 132 deletions(-) delete mode 100644 tests/Fixture/CustomMigrations/Version20240611065130.php rename tests/Fixture/{EdgeCases/Migrate/ORM => }/EntityInAnotherSchema/Article.php (68%) create mode 100644 tests/Fixture/TestMigrationKernel.php create mode 100644 tests/Integration/Migration/ResetDatabaseWithMigrationTest.php create mode 100644 tests/bootstrap-migrate.php diff --git a/.env b/.env index da52e373d..a27200d41 100644 --- a/.env +++ b/.env @@ -1,5 +1,4 @@ DATABASE_URL="mysql://root:1234@127.0.0.1:3307/foundry_test?serverVersion=5.7.42" MONGO_URL="mongodb://127.0.0.1:27018/dbName?compressors=disabled&gssapiServiceName=mongodb" -DATABASE_RESET_MODE="schema" USE_DAMA_DOCTRINE_TEST_BUNDLE="0" PHPUNIT_VERSION="9" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5df09b069..8e4f1ec33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: jobs: tests: - name: P:${{ matrix.php }}, S:${{ matrix.symfony }}, D:${{ matrix.database }}, PU:${{ matrix.phpunit }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}${{ matrix.use-dama == 1 && contains(matrix.database, 'sql') && ' (dama)' || '' }}${{ !contains(matrix.database, 'sql') && '' || matrix.use-migrate == 1 && ' (migrate)' || ' (schema)' }} + name: P:${{ matrix.php }}, S:${{ matrix.symfony }}, D:${{ matrix.database }}, PU:${{ matrix.phpunit }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}${{ matrix.use-dama == 1 && contains(matrix.database, 'sql') && ' (dama)' || '' }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -18,7 +18,6 @@ jobs: symfony: [ 6.4.*, 7.0.*, 7.1.* ] database: [ mysql, mongo ] use-dama: [ 1 ] - use-migrate: [ 0 ] phpunit: [ 9 ] exclude: - php: 8.1 @@ -31,70 +30,60 @@ jobs: symfony: '*' database: none use-dama: 1 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: highest symfony: '*' database: mysql|mongo use-dama: 1 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: highest symfony: '*' database: pgsql|mongo use-dama: 1 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: highest symfony: '*' database: pgsql use-dama: 0 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: highest symfony: '*' database: sqlite use-dama: 0 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: lowest symfony: '*' database: sqlite use-dama: 0 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: lowest symfony: '*' database: mysql use-dama: 1 - use-migrate: 0 phpunit: 9 - php: 8.3 deps: highest symfony: '*' database: mysql use-dama: 1 - use-migrate: 1 phpunit: 9 - php: 8.3 deps: highest symfony: '*' database: mysql|mongo use-dama: 1 - use-migrate: 0 phpunit: 10 - php: 8.3 deps: highest symfony: '*' database: mysql|mongo use-dama: 1 - use-migrate: 0 phpunit: 11 env: DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || contains(matrix.database, 'sqlite') && 'sqlite:///%kernel.project_dir%/var/data.db' || '' }} @@ -145,8 +134,63 @@ jobs: - name: Test run: ./phpunit shell: bash + + test-reset-database-with-migration: + name: Test migration - D:${{ matrix.database }}, ${{ matrix.use-dama == 1 && ' (dama)' || '' }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + database: [ mysql, pgsql, sqlite ] + use-dama: [ 0, 1 ] + exclude: + - database: sqlite + use-dama: 0 + env: + DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || 'sqlite:///%kernel.project_dir%/var/data.db' }} + MONGO_URL: '' + USE_DAMA_DOCTRINE_TEST_BUNDLE: ${{ matrix.use-dama == 1 && 1 || 0 }} + PHPUNIT_VERSION: 9 + services: + postgres: + image: ${{ contains(matrix.database, 'pgsql') && 'postgres:15' || '' }} env: - DATABASE_RESET_MODE: ${{ matrix.use-migrate == 1 && 'migrate' || 'schema' }} + POSTGRES_USER: root + POSTGRES_PASSWORD: root + POSTGRES_DB: foundry + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + coverage: none + tools: flex + + - name: Install dependencies + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + composer-options: --prefer-dist + env: + SYMFONY_REQUIRE: 7.1.* + + - name: Set up MySQL + if: contains(matrix.database, 'mysql') + run: sudo /etc/init.d/mysql start + + - name: Test + run: ./phpunit --testsuite migrate --bootstrap tests/bootstrap-migrate.php + shell: bash code-coverage: name: Code Coverage diff --git a/README.md b/README.md index 4472e2796..23c5c4c21 100644 --- a/README.md +++ b/README.md @@ -47,20 +47,15 @@ $ docker compose up --detach # install dependencies $ composer update -# run test suite with all available permutations -$ composer test - -# run only one permutation +# run main testsuite (with "schema" reset database strategy) +$ composer test-schema +# or $ ./phpunit -# run test suite with dama/doctrine-test-bundle -$ USE_DAMA_DOCTRINE_TEST_BUNDLE=1 vendor/bin/phpunit - -# run test suite with postgreSQL instead of MySQL -$ DATABASE_URL="postgresql://zenstruck:zenstruck@127.0.0.1:5433/zenstruck_foundry?serverVersion=15" vendor/bin/phpunit - -# run test suite with another PHPUnit version -$ PHPUNIT_VERSION=10 vendor/bin/phpunit +# run "migrate" testsuite (with "migrate" reset database strategy) +$ composer test-migrate +# or +$ ./phpunit --testsuite migrate --bootstrap tests/bootstrap-migrate.php ``` ### Overriding the default configuration @@ -69,7 +64,12 @@ You can override default environment variables by creating a `.env.local` file, ```bash # .env.local -DATABASE_URL="postgresql://zenstruck:zenstruck@127.0.0.1:5433/zenstruck_foundry?serverVersion=15" # enables postgreSQL instead of MySQL + +# change the database to postgreSQL... +DATABASE_URL="postgresql://zenstruck:zenstruck@127.0.0.1:5433/zenstruck_foundry?serverVersion=15" +# ...or to SQLite +DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" + MONGO_URL="" # disables Mongo USE_DAMA_DOCTRINE_TEST_BUNDLE="1" # enables dama/doctrine-test-bundle PHPUNIT_VERSION="11" # possible values: 9, 10, 11, 11.4 diff --git a/bin/console b/bin/console index 5944a814f..9ff51b3b3 100755 --- a/bin/console +++ b/bin/console @@ -2,9 +2,9 @@ run(); diff --git a/composer.json b/composer.json index 0e619e8b1..051b9042e 100644 --- a/composer.json +++ b/composer.json @@ -71,22 +71,15 @@ }, "scripts": { "test": [ - "@test-schema-no-dama", - "@test-migrate-no-dama", - "@test-schema-dama", - "@test-migrate-dama" + "@test-schema", + "@test-migrate" ], - "test-schema-no-dama": "DATABASE_RESET_MODE=schema USE_DAMA_DOCTRINE_TEST_BUNDLE=0 ./phpunit", - "test-migrate-no-dama": "DATABASE_RESET_MODE=migrate USE_DAMA_DOCTRINE_TEST_BUNDLE=0 ./phpunit", - "test-schema-dama": "DATABASE_RESET_MODE=schema USE_DAMA_DOCTRINE_TEST_BUNDLE=1 ./phpunit", - "test-migrate-dama": "DATABASE_RESET_MODE=migrate USE_DAMA_DOCTRINE_TEST_BUNDLE=1 ./phpunit" + "test-schema": "./phpunit", + "test-migrate": "./phpunit --testsuite migrate --bootstrap tests/bootstrap-migrate.php" }, "scripts-descriptions": { - "test": "Run all test permutations", - "test-schema-no-dama": "Test with schema reset (no dama/doctrine-test-bundle)", - "test-migrate-no-dama": "Test with migrations reset (no dama/doctrine-test-bundle)", - "test-schema-dama": "Test with schema reset and dama/doctrine-test-bundle", - "test-migrate-dama": "Test with migrations reset and dama/doctrine-test-bundle" + "test-schema": "Test with schema reset", + "test-migrate": "Test with migrations reset" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/phpunit-10.xml.dist b/phpunit-10.xml.dist index 1727f9b8b..ce6671332 100644 --- a/phpunit-10.xml.dist +++ b/phpunit-10.xml.dist @@ -14,8 +14,9 @@ - + tests + tests/Integration/Migration/ResetDatabaseWithMigrationTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6aee915ff..dcad3f887 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,6 +7,7 @@ colors="true" failOnRisky="true" failOnWarning="true" + defaultTestSuite="main" > @@ -16,8 +17,12 @@ - + tests + tests/Integration/Migration/ResetDatabaseWithMigrationTest.php + + + tests/Integration/Migration/ResetDatabaseWithMigrationTest.php diff --git a/tests/Fixture/CustomMigrations/Version20240611065130.php b/tests/Fixture/CustomMigrations/Version20240611065130.php deleted file mode 100644 index 9d51237ff..000000000 --- a/tests/Fixture/CustomMigrations/Version20240611065130.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// to "Migrations" directory on boot (cf. bootstrap.php) - -namespace Zenstruck\Foundry\Tests\Fixture\Migrations; - -use Doctrine\DBAL\Schema\Schema; -use Doctrine\Migrations\AbstractMigration; -use Zenstruck\Foundry\Tests\Fixture\EdgeCases\Migrate\ORM\EntityInAnotherSchema\Article; - -/** - * Create custom "cms" schema ({@see Article}) to ensure "migrate" mode is still working with multiple schemas. - * Note: the doctrine:migrations:diff command doesn't seem able to add this custom "CREATE SCHEMA" automatically. - * - * @see https://github.com/zenstruck/foundry/issues/618 - */ -final class Version20240611065130 extends AbstractMigration -{ - public function getDescription(): string - { - return 'Create custom "cms" schema.'; - } - - public function up(Schema $schema): void - { - $this->addSql('CREATE SCHEMA cms'); - } - - public function down(Schema $schema): void - { - $this->addSql('DROP SCHEMA cms'); - } -} diff --git a/tests/Fixture/EdgeCases/Migrate/ORM/EntityInAnotherSchema/Article.php b/tests/Fixture/EntityInAnotherSchema/Article.php similarity index 68% rename from tests/Fixture/EdgeCases/Migrate/ORM/EntityInAnotherSchema/Article.php rename to tests/Fixture/EntityInAnotherSchema/Article.php index fba361efc..e95aa52b2 100644 --- a/tests/Fixture/EdgeCases/Migrate/ORM/EntityInAnotherSchema/Article.php +++ b/tests/Fixture/EntityInAnotherSchema/Article.php @@ -11,11 +11,17 @@ * file that was distributed with this source code. */ -namespace Zenstruck\Foundry\Tests\Fixture\EdgeCases\Migrate\ORM\EntityInAnotherSchema; +namespace Zenstruck\Foundry\Tests\Fixture\EntityInAnotherSchema; use Doctrine\ORM\Mapping as ORM; use Zenstruck\Foundry\Tests\Fixture\Model\Base; +/** + * Create custom "cms" schema ({@see Article}) to ensure "migrate" mode is still working with multiple schemas. + * Note: this entity is added to mapping only for PostgreSQ, as it is the only supported DBMS which handles multiple schemas. + * + * @see https://github.com/zenstruck/foundry/issues/618 + */ #[ORM\Entity] #[ORM\Table(name: 'article', schema: 'cms')] class Article extends Base diff --git a/tests/Fixture/TestKernel.php b/tests/Fixture/TestKernel.php index 049c13c7d..9bff522fe 100644 --- a/tests/Fixture/TestKernel.php +++ b/tests/Fixture/TestKernel.php @@ -13,7 +13,6 @@ use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; use Psr\Log\NullLogger; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; @@ -44,7 +43,6 @@ public function registerBundles(): iterable if (\getenv('DATABASE_URL')) { yield new DoctrineBundle(); - yield new DoctrineMigrationsBundle(); } if (\getenv('MONGO_URL')) { @@ -74,7 +72,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], 'orm' => [ 'reset' => [ - 'mode' => \getenv('DATABASE_RESET_MODE') ?: AbstractORMPersistenceStrategy::RESET_MODE_SCHEMA, + 'mode' => AbstractORMPersistenceStrategy::RESET_MODE_SCHEMA, ], ], ]); @@ -105,27 +103,22 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], ]); - if (AbstractORMPersistenceStrategy::RESET_MODE_MIGRATE === \getenv('DATABASE_RESET_MODE')) { + // doctrine only handles different schema with postgres + if (str_starts_with(\getenv('DATABASE_URL'), 'postgresql')) { $c->loadFromExtension('doctrine', [ 'orm' => [ 'mappings' => [ 'Migrate' => [ 'is_bundle' => false, 'type' => 'attribute', - 'dir' => '%kernel.project_dir%/tests/Fixture/EdgeCases/Migrate/ORM', - 'prefix' => 'Zenstruck\Foundry\Tests\Fixture\EdgeCases\Migrate\ORM', + 'dir' => '%kernel.project_dir%/tests/Fixture/EntityInAnotherSchema', + 'prefix' => 'Zenstruck\Foundry\Tests\Fixture\EntityInAnotherSchema', 'alias' => 'Migrate', ], ], ], ]); } - - $c->loadFromExtension('doctrine_migrations', [ - 'migrations_paths' => [ - 'Zenstruck\\Foundry\\Tests\\Fixture\\Migrations' => '%kernel.project_dir%/tests/Fixture/Migrations', - ], - ]); } if (\getenv('MONGO_URL')) { diff --git a/tests/Fixture/TestMigrationKernel.php b/tests/Fixture/TestMigrationKernel.php new file mode 100644 index 000000000..39a305e7e --- /dev/null +++ b/tests/Fixture/TestMigrationKernel.php @@ -0,0 +1,125 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zenstruck\Foundry\Tests\Fixture; + +use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle; +use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; +use Psr\Log\NullLogger; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Zenstruck\Foundry\ORM\AbstractORMPersistenceStrategy; +use Zenstruck\Foundry\Tests\Fixture\Stories\GlobalInvokableService; +use Zenstruck\Foundry\Tests\Fixture\Stories\GlobalStory; +use Zenstruck\Foundry\ZenstruckFoundryBundle; + +/** + * @author Nicolas PHILIPPE + */ +final class TestMigrationKernel extends Kernel +{ + use MicroKernelTrait; + + public function registerBundles(): iterable + { + yield new FrameworkBundle(); + yield new DoctrineBundle(); + yield new DoctrineMigrationsBundle(); + + yield new ZenstruckFoundryBundle(); + + if (\getenv('USE_DAMA_DOCTRINE_TEST_BUNDLE')) { + yield new DAMADoctrineTestBundle(); + } + } + + protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void + { + $c->loadFromExtension('framework', [ + 'http_method_override' => false, + 'secret' => 'S3CRET', + 'router' => ['utf8' => true], + 'test' => true, + ]); + + $c->loadFromExtension('zenstruck_foundry', [ + 'global_state' => [ + GlobalStory::class, + GlobalInvokableService::class, + ], + 'orm' => [ + 'reset' => [ + 'mode' => AbstractORMPersistenceStrategy::RESET_MODE_MIGRATE, + ], + ], + ]); + $c->loadFromExtension('doctrine', [ + 'dbal' => ['url' => '%env(resolve:DATABASE_URL)%', 'use_savepoints' => true], + 'orm' => [ + 'auto_generate_proxy_classes' => true, + 'auto_mapping' => true, + 'mappings' => [ + 'Entity' => [ + 'is_bundle' => false, + 'type' => 'attribute', + 'dir' => '%kernel.project_dir%/tests/Fixture/Entity', + 'prefix' => 'Zenstruck\Foundry\Tests\Fixture\Entity', + 'alias' => 'Entity', + ], + 'Model' => [ + 'is_bundle' => false, + 'type' => 'attribute', + 'dir' => '%kernel.project_dir%/tests/Fixture/Model', + 'prefix' => 'Zenstruck\Foundry\Tests\Fixture\Model', + 'alias' => 'Model', + ], + ], + 'controller_resolver' => ['auto_mapping' => true], + ], + ]); + + // doctrine only handles different schema with postgres + if (str_starts_with(\getenv('DATABASE_URL') ?: '', 'postgresql')) { + $c->loadFromExtension('doctrine', [ + 'orm' => [ + 'mappings' => [ + 'Migrate' => [ + 'is_bundle' => false, + 'type' => 'attribute', + 'dir' => '%kernel.project_dir%/tests/Fixture/EntityInAnotherSchema', + 'prefix' => 'Zenstruck\Foundry\Tests\Fixture\EntityInAnotherSchema', + 'alias' => 'Migrate', + ], + ], + ], + ]); + } + + $c->loadFromExtension('doctrine_migrations', [ + 'migrations_paths' => [ + 'Zenstruck\\Foundry\\Tests\\Fixture\\Migrations' => '%kernel.project_dir%/tests/Fixture/Migrations', + ], + 'transactional' => false, + ]); + + $c->register('logger', NullLogger::class); + $c->register(GlobalInvokableService::class); + } + + protected function configureRoutes(RoutingConfigurator $routes): void + { + } +} diff --git a/tests/Integration/Migration/ResetDatabaseWithMigrationTest.php b/tests/Integration/Migration/ResetDatabaseWithMigrationTest.php new file mode 100644 index 000000000..b9b4c673e --- /dev/null +++ b/tests/Integration/Migration/ResetDatabaseWithMigrationTest.php @@ -0,0 +1,73 @@ + + */ +final class ResetDatabaseWithMigrationTest extends KernelTestCase +{ + use Factories; + use ResetDatabase; + use RequiresORM; + + /** + * @test + */ + public function it_can_store_object(): void + { + StandardContactFactory::assert()->count(0); + + StandardContactFactory::createOne(); + + StandardContactFactory::assert()->count(1); + } + + /** + * @test + * @depends it_can_store_object + */ + public function it_starts_from_fresh_db(): void + { + StandardContactFactory::assert()->count(0); + } + + /** + * @test + */ + public function global_objects_are_created(): void + { + repository(GlobalEntity::class)->assert()->count(2); + } + + /** + * @test + */ + public function can_create_object_in_another_schema(): void + { + if (!str_starts_with(\getenv('DATABASE_URL') ?: '', 'postgresql')) { + self::markTestSkipped('PostgreSQL needed.'); + } + + persist(Article::class, ['title' => 'Hello World!']); + repository(Article::class)->assert()->count(1); + } + + protected static function getKernelClass(): string + { + return TestMigrationKernel::class; + } +} diff --git a/tests/bootstrap-migrate.php b/tests/bootstrap-migrate.php new file mode 100644 index 000000000..162e3716a --- /dev/null +++ b/tests/bootstrap-migrate.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Component\Console\Input\StringInput; +use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Dotenv\Dotenv; +use Symfony\Component\ErrorHandler\ErrorHandler; +use Symfony\Component\Filesystem\Filesystem; +use Zenstruck\Foundry\Tests\Fixture\TestMigrationKernel; + +require \dirname(__DIR__).'/vendor/autoload.php'; + +$fs = new Filesystem(); + +$fs->remove(__DIR__.'/../var'); + +(new Dotenv())->usePutenv()->loadEnv(__DIR__.'/../.env'); + +$fs->remove(__DIR__.'/Fixture/Migrations'); +$fs->mkdir(__DIR__.'/Fixture/Migrations'); + +$kernel = new TestMigrationKernel('test', true); +$kernel->boot(); + +$application = new Application($kernel); +$application->setAutoExit(false); + +$application->run(new StringInput('doctrine:database:drop --if-exists --force'), new NullOutput()); +$application->run(new StringInput('doctrine:database:create'), new NullOutput()); +$application->run(new StringInput('doctrine:migrations:diff'), new NullOutput()); +$application->run(new StringInput('doctrine:database:drop --force'), new NullOutput()); + +$kernel->shutdown(); + +\set_exception_handler([new ErrorHandler(), 'handleException']); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 51fb6d505..4d9bb4c61 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -9,15 +9,9 @@ * file that was distributed with this source code. */ -use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Input\StringInput; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\ErrorHandler; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; -use Zenstruck\Foundry\ORM\AbstractORMPersistenceStrategy; -use Zenstruck\Foundry\Tests\Fixture\TestKernel; require \dirname(__DIR__).'/vendor/autoload.php'; @@ -27,29 +21,4 @@ (new Dotenv())->usePutenv()->loadEnv(__DIR__.'/../.env'); -if (\getenv('DATABASE_URL') && AbstractORMPersistenceStrategy::RESET_MODE_MIGRATE === \getenv('DATABASE_RESET_MODE')) { - $fs->remove(__DIR__.'/Fixture/Migrations'); - $fs->mkdir(__DIR__.'/Fixture/Migrations'); - - $kernel = new TestKernel('test', true); - $kernel->boot(); - - $application = new Application($kernel); - $application->setAutoExit(false); - - $application->run(new StringInput('doctrine:database:drop --if-exists --force'), new NullOutput()); - $application->run(new StringInput('doctrine:database:create'), new NullOutput()); - $application->run(new StringInput('doctrine:migrations:diff'), new NullOutput()); - $application->run(new StringInput('doctrine:database:drop --force'), new NullOutput()); - - // restore custom migrations - // this must be after "doctrine:migrations:diff" otherwise - // Doctrine is not able to run its diff command - foreach ((new Finder())->files()->in(__DIR__.'/Fixture/CustomMigrations') as $customMigrationFile) { - $fs->copy($customMigrationFile->getRealPath(), __DIR__.'/Fixture/Migrations/'.$customMigrationFile->getFilename()); - } - - $kernel->shutdown(); -} - \set_exception_handler([new ErrorHandler(), 'handleException']);