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..a49a78cf5 100644 --- a/libs/doctrine-retry-bundle/composer.json +++ b/libs/doctrine-retry-bundle/composer.json @@ -12,19 +12,22 @@ "require": { "php": "^8.4", "doctrine/dbal": "^4.2", - "doctrine/doctrine-bundle": "^2.1", + "doctrine/doctrine-bundle": "^3.0", "keboola/retry": "^0.5.0", - "symfony/dependency-injection": "^7.0|^6.4", - "symfony/http-kernel": "^7.0|^6.4" + "symfony/dependency-injection": "^8.0|^7.4", + "symfony/http-kernel": "^8.0|^7.4" }, "require-dev": { "ext-pdo": "*", "ihsw/toxiproxy-php-client": "^3.0", - "keboola/coding-standard": "^15.1", + "keboola/coding-standard": "^16.0", "monolog/monolog": "^3.9", "phpstan/phpstan": "^2.1", + "phpstan/phpstan-doctrine": "^2.0", "phpstan/phpstan-phpunit": "^2.0", - "phpunit/phpunit": "^12.1" + "phpstan/phpstan-symfony": "^2.0", + "phpunit/phpunit": "^13.0", + "symfony/dotenv": "^8.0|^7.4" }, "autoload": { "psr-4": { @@ -45,9 +48,9 @@ }, "scripts": { "phpunit": "phpunit", - "phpstan": "phpstan analyse", - "phpcs": "phpcs -n --ignore=vendor --extensions=php .", - "phpcbf": "phpcbf -n --ignore=vendor --extensions=php .", + "phpstan": "phpstan analyse --no-progress", + "phpcs": "phpcs --extensions=php src tests", + "phpcbf": "phpcbf --extensions=php src tests", "build": [ "@composer validate --no-check-publish --no-check-all", "@phpcs", diff --git a/libs/doctrine-retry-bundle/phpstan.neon b/libs/doctrine-retry-bundle/phpstan.neon deleted file mode 100644 index 4026fdc49..000000000 --- a/libs/doctrine-retry-bundle/phpstan.neon +++ /dev/null @@ -1,10 +0,0 @@ -parameters: - level: max - paths: - - src - - tests - ignoreErrors: - - identifier: missingType.iterableValue - -includes: - - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/libs/doctrine-retry-bundle/phpstan.neon.dist b/libs/doctrine-retry-bundle/phpstan.neon.dist new file mode 100644 index 000000000..78b8fc08e --- /dev/null +++ b/libs/doctrine-retry-bundle/phpstan.neon.dist @@ -0,0 +1,13 @@ +parameters: + level: max + paths: + - src + - tests + + ignoreErrors: + - + identifier: missingType.iterableValue + +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + diff --git a/libs/doctrine-retry-bundle/phpunit.xml.dist b/libs/doctrine-retry-bundle/phpunit.xml.dist index afb7d940e..5d5e806fe 100644 --- a/libs/doctrine-retry-bundle/phpunit.xml.dist +++ b/libs/doctrine-retry-bundle/phpunit.xml.dist @@ -1,21 +1,15 @@ - - + bootstrap="tests/bootstrap.php"> + src - - + diff --git a/libs/doctrine-retry-bundle/src/Database/Retry/Driver.php b/libs/doctrine-retry-bundle/src/Database/Retry/Driver.php index 340462fbf..d3ce50f89 100644 --- a/libs/doctrine-retry-bundle/src/Database/Retry/Driver.php +++ b/libs/doctrine-retry-bundle/src/Database/Retry/Driver.php @@ -5,6 +5,7 @@ namespace Keboola\DoctrineRetryBundle\Database\Retry; use Doctrine\DBAL\Driver as DriverInterface; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; use Retry\RetryProxyInterface; @@ -28,7 +29,7 @@ public function __construct(DriverInterface $driver, RetryProxyInterface $retryP public function connect(array $params): DriverInterface\Connection { /** @var DriverInterface\Connection $result */ - $result = $this->retryProxy->call(fn() => parent::connect($params)); + $result = $this->retryProxy->call(fn(): Connection => parent::connect($params)); return $result; } } 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)); + } +}