diff --git a/libs/doctrine-retry-bundle/README.md b/libs/doctrine-retry-bundle/README.md index 26cbfa8eb..dee0a91c0 100644 --- a/libs/doctrine-retry-bundle/README.md +++ b/libs/doctrine-retry-bundle/README.md @@ -16,6 +16,19 @@ doctrine: ``` ## Environment +The tests connect to MySQL through a [Toxiproxy](https://github.com/Shopify/toxiproxy) instance +(used to simulate connection failures). Both are provided by the `dev-doctrine-retry-bundle` +Docker Compose service, so the simplest way to run them is: +```bash +docker compose run --rm dev-doctrine-retry-bundle composer ci +``` + +The following variables are required: ``` -TEST_DATABASE_URL - database connection URL (mysql://user:secret@localhost/mydb) +TEST_DATABASE_HOST - MySQL host (e.g. mysql) +TEST_DATABASE_PORT - MySQL port (e.g. 3306) +TEST_DATABASE_USER - MySQL user (e.g. root) +TEST_DATABASE_PASSWORD - MySQL password +TEST_DATABASE_DB - MySQL database name (e.g. testdatabase) +TEST_PROXY_HOST - Toxiproxy host (e.g. toxiproxy); its API is reached at http://:8474 ``` diff --git a/libs/doctrine-retry-bundle/composer.json b/libs/doctrine-retry-bundle/composer.json index aa913dad7..de98133dc 100644 --- a/libs/doctrine-retry-bundle/composer.json +++ b/libs/doctrine-retry-bundle/composer.json @@ -24,7 +24,8 @@ "monolog/monolog": "^3.9", "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", - "phpunit/phpunit": "^12.1" + "phpunit/phpunit": "^12.1", + "symfony/dotenv": "^6.0|^7.0" }, "autoload": { "psr-4": { diff --git a/libs/doctrine-retry-bundle/tests/bootstrap.php b/libs/doctrine-retry-bundle/tests/bootstrap.php index a075e1e88..1949c8aeb 100644 --- a/libs/doctrine-retry-bundle/tests/bootstrap.php +++ b/libs/doctrine-retry-bundle/tests/bootstrap.php @@ -2,4 +2,24 @@ declare(strict_types=1); -require_once __DIR__ . '/../vendor/autoload.php'; +use Symfony\Component\Dotenv\Dotenv; + +require __DIR__ . '/../vendor/autoload.php'; + +if (file_exists(dirname(__DIR__).'/.env.local')) { + (new Dotenv())->usePutenv()->bootEnv(dirname(__DIR__).'/.env.local', 'dev', []); +} + +$requiredEnvs = [ + 'TEST_DATABASE_HOST', + 'TEST_DATABASE_PORT', + 'TEST_DATABASE_USER', + 'TEST_DATABASE_PASSWORD', + 'TEST_DATABASE_DB', + 'TEST_PROXY_HOST', +]; +foreach ($requiredEnvs as $env) { + if (empty(getenv($env))) { + throw new Exception(sprintf('Environment variable "%s" is empty', $env)); + } +}