Install DAMA

This commit is contained in:
myrmidex 2026-06-17 20:54:25 +02:00
parent afb99a11ec
commit 21110c6e70
8 changed files with 139 additions and 2 deletions

View file

@ -27,6 +27,7 @@
"symfony/security-bundle": "8.1.*", "symfony/security-bundle": "8.1.*",
"symfony/serializer": "8.1.*", "symfony/serializer": "8.1.*",
"symfony/twig-bundle": "8.1.*", "symfony/twig-bundle": "8.1.*",
"symfony/uid": "8.1.*",
"symfony/validator": "8.1.*", "symfony/validator": "8.1.*",
"symfony/yaml": "8.1.*" "symfony/yaml": "8.1.*"
}, },
@ -85,6 +86,7 @@
} }
}, },
"require-dev": { "require-dev": {
"dama/doctrine-test-bundle": "^8.6",
"friendsofphp/php-cs-fixer": "^3.95", "friendsofphp/php-cs-fixer": "^3.95",
"phpstan/extension-installer": "^1.4", "phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.2", "phpstan/phpstan": "^2.2",

73
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "6b5cd0f778cc640d42c1d048d7f5e83b", "content-hash": "8096a72d560f2d6e1c5aafb6175ba005",
"packages": [ "packages": [
{ {
"name": "api-platform/doctrine-common", "name": "api-platform/doctrine-common",
@ -7594,6 +7594,75 @@
], ],
"time": "2024-05-06T16:37:16+00:00" "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", "name": "ergebnis/agent-detector",
"version": "1.2.0", "version": "1.2.0",
@ -11043,5 +11112,5 @@
"ext-iconv": "*" "ext-iconv": "*"
}, },
"platform-dev": {}, "platform-dev": {},
"plugin-api-version": "2.6.0" "plugin-api-version": "2.9.0"
} }

View file

@ -9,4 +9,5 @@ return [
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
]; ];

View file

@ -0,0 +1,5 @@
when@test:
dama_doctrine_test:
enable_static_connection: true
enable_static_meta_data_cache: true
enable_static_query_cache: true

View file

@ -1580,6 +1580,12 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* generate_final_classes?: bool|Param, // Default: true * generate_final_classes?: bool|Param, // Default: true
* generate_final_entities?: bool|Param, // Default: false * 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<mixed>,
* }
* @psalm-type ConfigType = array{ * @psalm-type ConfigType = array{
* imports?: ImportsConfig, * imports?: ImportsConfig,
* parameters?: ParametersConfig, * parameters?: ParametersConfig,
@ -1627,6 +1633,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* doctrine_migrations?: DoctrineMigrationsConfig, * doctrine_migrations?: DoctrineMigrationsConfig,
* nelmio_cors?: NelmioCorsConfig, * nelmio_cors?: NelmioCorsConfig,
* api_platform?: ApiPlatformConfig, * api_platform?: ApiPlatformConfig,
* dama_doctrine_test?: DamaDoctrineTestConfig,
* }, * },
* ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias * ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias
* imports?: ImportsConfig, * imports?: ImportsConfig,

View file

@ -40,5 +40,6 @@
</source> </source>
<extensions> <extensions>
<bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions> </extensions>
</phpunit> </phpunit>

View file

@ -13,6 +13,9 @@
"src/ApiResource/.gitignore" "src/ApiResource/.gitignore"
] ]
}, },
"dama/doctrine-test-bundle": {
"version": "v8.6.0"
},
"doctrine/deprecations": { "doctrine/deprecations": {
"version": "1.1", "version": "1.1",
"recipe": { "recipe": {

View file

@ -1,5 +1,6 @@
<?php <?php
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php'; require dirname(__DIR__).'/vendor/autoload.php';
@ -11,3 +12,51 @@ if (method_exists(Dotenv::class, 'bootEnv')) {
if ($_SERVER['APP_DEBUG']) { if ($_SERVER['APP_DEBUG']) {
umask(0000); umask(0000);
} }
// Bootstrap the test database so that a fresh checkout / CI never hits
// "database does not exist" or schema drift.
//
// Strategy: use the Symfony kernel (test env) to reach Doctrine, then:
// 1. CREATE DATABASE IF NOT EXISTS — via the DBAL schema manager
// 2. Run pending migrations — via the MigrationsBundle console command
//
// This runs once per phpunit invocation (not per test — DAMA wraps each test
// in a transaction and rolls it back, so the schema itself must already exist).
(function (): void {
$kernel = new \App\Kernel('test', true);
$kernel->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();
})();