diff --git a/composer.json b/composer.json index 223ac3b..5857e37 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "symfony/security-bundle": "8.1.*", "symfony/serializer": "8.1.*", "symfony/twig-bundle": "8.1.*", + "symfony/uid": "8.1.*", "symfony/validator": "8.1.*", "symfony/yaml": "8.1.*" }, @@ -85,6 +86,7 @@ } }, "require-dev": { + "dama/doctrine-test-bundle": "^8.6", "friendsofphp/php-cs-fixer": "^3.95", "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^2.2", diff --git a/composer.lock b/composer.lock index 79cf256..fdb9c94 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6b5cd0f778cc640d42c1d048d7f5e83b", + "content-hash": "8096a72d560f2d6e1c5aafb6175ba005", "packages": [ { "name": "api-platform/doctrine-common", @@ -7594,6 +7594,75 @@ ], "time": "2024-05-06T16:37:16+00:00" }, + { + "name": "dama/doctrine-test-bundle", + "version": "v8.6.0", + "source": { + "type": "git", + "url": "https://github.com/dmaicher/doctrine-test-bundle.git", + "reference": "f7e3487643e685432f7e27c50cac64e9f8c515a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dmaicher/doctrine-test-bundle/zipball/f7e3487643e685432f7e27c50cac64e9f8c515a4", + "reference": "f7e3487643e685432f7e27c50cac64e9f8c515a4", + "shasum": "" + }, + "require": { + "doctrine/dbal": "^3.3 || ^4.0", + "doctrine/doctrine-bundle": "^2.11.0 || ^3.0", + "php": ">= 8.2", + "psr/cache": "^2.0 || ^3.0", + "symfony/cache": "^6.4 || ^7.3 || ^8.0", + "symfony/framework-bundle": "^6.4 || ^7.3 || ^8.0" + }, + "conflict": { + "phpunit/phpunit": "<11.0" + }, + "require-dev": { + "behat/behat": "^3.0", + "friendsofphp/php-cs-fixer": "^3.27", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^11.5.41|| ^12.3.14", + "symfony/dotenv": "^6.4 || ^7.3 || ^8.0", + "symfony/process": "^6.4 || ^7.3 || ^8.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "DAMA\\DoctrineTestBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "David Maicher", + "email": "mail@dmaicher.de" + } + ], + "description": "Symfony bundle to isolate doctrine database tests and improve test performance", + "keywords": [ + "doctrine", + "isolation", + "performance", + "symfony", + "testing", + "tests" + ], + "support": { + "issues": "https://github.com/dmaicher/doctrine-test-bundle/issues", + "source": "https://github.com/dmaicher/doctrine-test-bundle/tree/v8.6.0" + }, + "time": "2026-01-21T07:39:44+00:00" + }, { "name": "ergebnis/agent-detector", "version": "1.2.0", @@ -11043,5 +11112,5 @@ "ext-iconv": "*" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/config/bundles.php b/config/bundles.php index 140f5fd..a3ed082 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -9,4 +9,5 @@ return [ Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true], ]; diff --git a/config/packages/dama_doctrine_test_bundle.yaml b/config/packages/dama_doctrine_test_bundle.yaml new file mode 100644 index 0000000..3482cba --- /dev/null +++ b/config/packages/dama_doctrine_test_bundle.yaml @@ -0,0 +1,5 @@ +when@test: + dama_doctrine_test: + enable_static_connection: true + enable_static_meta_data_cache: true + enable_static_query_cache: true diff --git a/config/reference.php b/config/reference.php index 8055c49..ba0ae39 100644 --- a/config/reference.php +++ b/config/reference.php @@ -1580,6 +1580,12 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * generate_final_classes?: bool|Param, // Default: true * generate_final_entities?: bool|Param, // Default: false * } + * @psalm-type DamaDoctrineTestConfig = array{ + * enable_static_connection?: mixed, // Default: true + * enable_static_meta_data_cache?: bool|Param, // Default: true + * enable_static_query_cache?: bool|Param, // Default: true + * connection_keys?: list, + * } * @psalm-type ConfigType = array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, @@ -1627,6 +1633,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * doctrine_migrations?: DoctrineMigrationsConfig, * nelmio_cors?: NelmioCorsConfig, * api_platform?: ApiPlatformConfig, + * dama_doctrine_test?: DamaDoctrineTestConfig, * }, * ... + diff --git a/symfony.lock b/symfony.lock index 84b30b1..cdf8a52 100644 --- a/symfony.lock +++ b/symfony.lock @@ -13,6 +13,9 @@ "src/ApiResource/.gitignore" ] }, + "dama/doctrine-test-bundle": { + "version": "v8.6.0" + }, "doctrine/deprecations": { "version": "1.1", "recipe": { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 47a5855..eceb9e0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,6 @@ boot(); + + $container = $kernel->getContainer(); + + /** @var \Doctrine\DBAL\Connection $connection */ + $connection = $container->get('doctrine')->getConnection(); + + // 1. Ensure the database exists. + $schemaManager = $connection->createSchemaManager(); + $dbName = $connection->getDatabase(); + + if (!in_array($dbName, $schemaManager->listDatabases(), true)) { + $schemaManager->createDatabase($dbName); + } + + // 2. Run any pending migrations idempotently. + // --no-interaction suppresses the "are you sure?" prompt. + /** @var \Symfony\Component\Console\Application $application */ + $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel); + $application->setAutoExit(false); + + $exitCode = $application->run( + new \Symfony\Component\Console\Input\ArrayInput([ + 'command' => 'doctrine:migrations:migrate', + '--no-interaction' => true, + ]), + new \Symfony\Component\Console\Output\NullOutput(), + ); + + if ($exitCode !== 0) { + fwrite(STDERR, "bootstrap.php: doctrine:migrations:migrate failed (exit {$exitCode})\n"); + exit(1); + } + + $kernel->shutdown(); +})();