From 252225f0ea2f4c75622e228273d1bc1f2ec42ae8 Mon Sep 17 00:00:00 2001 From: "Nikola Svitlica a.k.a TheCelavi" Date: Thu, 11 Dec 2025 10:00:17 +0100 Subject: [PATCH 1/2] Fixing CI --- compose.yaml | 2 +- docker/php/Dockerfile | 2 ++ phpunit.php | 5 +++ phpunit.xml | 2 +- .../config/services/middleware.php | 2 +- .../tests/Fixtures/Dbal/MySqlFactory.php | 36 ++++++++++++++----- 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 phpunit.php diff --git a/compose.yaml b/compose.yaml index f3ac58e..458c0b6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -4,7 +4,7 @@ services: build: context: './docker/php' args: - SYSTEM_TIMEZONE: ${SYSTEM_TIMEZONE:-Europe/Belgrade} + SYSTEM_TIMEZONE: ${SYSTEM_TIMEZONE:-UTC} environment: PHP_XDEBUG_MODE: ${PHP_XDEBUG_MODE:-debug} PHP_XDEBUG_REMOTE_PORT: ${PHP_XDEBUG_REMOTE_PORT:-9000} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index f973e10..d11de5c 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -99,4 +99,6 @@ RUN composer global config --no-plugins allow-plugins.infection/extension-instal # # ##################################################################################### +RUN git config --global --add safe.directory /var/www/html + WORKDIR /var/www/html \ No newline at end of file diff --git a/phpunit.php b/phpunit.php new file mode 100644 index 0000000..79c43b5 --- /dev/null +++ b/phpunit.php @@ -0,0 +1,5 @@ +tag('runopencode.query.middleware', [ 'alias' => 'slow', ]); - + $configurator ->set(ConvertMiddleware::class) ->arg('$registry', AdapterRegistry::class) diff --git a/src/RunOpenCode/Component/Query/tests/Fixtures/Dbal/MySqlFactory.php b/src/RunOpenCode/Component/Query/tests/Fixtures/Dbal/MySqlFactory.php index 4a622ca..19ab4ab 100644 --- a/src/RunOpenCode/Component/Query/tests/Fixtures/Dbal/MySqlFactory.php +++ b/src/RunOpenCode/Component/Query/tests/Fixtures/Dbal/MySqlFactory.php @@ -15,6 +15,8 @@ */ final class MySqlFactory { + private const int MAX_ATTEMPTS = 15; + private static self $instance; public static function instance(): self @@ -37,14 +39,32 @@ public function create(MySqlDatabase $database): array $configuration->setMiddlewares([new DbalLoggingMiddleware($logger)]); - $connection = DriverManager::getConnection([ - 'driver' => 'mysqli', - 'dbname' => $database->value, - 'user' => 'roc', - 'password' => 'roc', - 'host' => 'mysql.local', - ], $configuration); + for ($i = 0; $i < self::MAX_ATTEMPTS; ++$i) { + $connection = DriverManager::getConnection([ + 'driver' => 'mysqli', + 'dbname' => $database->value, + 'user' => 'roc', + 'password' => 'roc', + 'host' => 'mysql.local', + ], $configuration); + + if (!$connection->isConnected()) { + return [$connection, $logger]; + } + + try { + $connection->getServerVersion(); + + return [$connection, $logger]; + } catch (\Exception) { + \sleep(1); + } + } - return [$connection, $logger]; + throw new \RuntimeException(\sprintf( + 'Unable to connect to database "%s" after %d attempts.', + $database->value, + self::MAX_ATTEMPTS, + )); } } From 7e6706c7878858352d1336b2940fd0a5390161cc Mon Sep 17 00:00:00 2001 From: "Nikola Svitlica a.k.a TheCelavi" Date: Thu, 11 Dec 2025 12:16:22 +0100 Subject: [PATCH 2/2] Fixed issue with parser file patterns; --- src/RunOpenCode/Bundle/QueryBundle/README.md | 5 +++ .../config/definition/middleware.php | 2 + .../QueryBundle/config/definition/parser.php | 6 +-- .../src/Parser/ContextAwareVariables.php | 8 ++-- .../Component/Query/src/Parser/Variables.php | 8 ++++ .../Query/tests/Functions/ToRegexTest.php | 43 +++++++++++++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 src/RunOpenCode/Component/Query/tests/Functions/ToRegexTest.php diff --git a/src/RunOpenCode/Bundle/QueryBundle/README.md b/src/RunOpenCode/Bundle/QueryBundle/README.md index fd6db96..7638867 100644 --- a/src/RunOpenCode/Bundle/QueryBundle/README.md +++ b/src/RunOpenCode/Bundle/QueryBundle/README.md @@ -13,3 +13,8 @@ Bundle integrates [Query Component](https://github.com/RunOpenCode/query) into S - [Send pull requests](https://github.com/RunOpenCode/phplib/pulls) - [Changelog](https://github.com/RunOpenCode/phplib/blob/master/CHANGELOG) - [License](https://github.com/RunOpenCode/phplib/blob/master/LICENSE) + +## TODO + +- [ ] Add compile time check for replica, verify that replica connection exists. If replica is disabled, verification + should emit only warning. diff --git a/src/RunOpenCode/Bundle/QueryBundle/config/definition/middleware.php b/src/RunOpenCode/Bundle/QueryBundle/config/definition/middleware.php index 061b0b5..db055e5 100644 --- a/src/RunOpenCode/Bundle/QueryBundle/config/definition/middleware.php +++ b/src/RunOpenCode/Bundle/QueryBundle/config/definition/middleware.php @@ -36,6 +36,8 @@ 'cache', 'parser', 'convert', + 'retry', + 'slow' ]) ->scalarPrototype()->end() ->end() diff --git a/src/RunOpenCode/Bundle/QueryBundle/config/definition/parser.php b/src/RunOpenCode/Bundle/QueryBundle/config/definition/parser.php index 945d8c8..0f7a66f 100644 --- a/src/RunOpenCode/Bundle/QueryBundle/config/definition/parser.php +++ b/src/RunOpenCode/Bundle/QueryBundle/config/definition/parser.php @@ -16,7 +16,7 @@ ->addDefaultsIfNotSet() ->children() ->arrayNode('pattern') - ->defaultValue(['*.sql', '*.dql']) + ->defaultValue(['/^.+\.(sql|dql)$/i']) ->beforeNormalization() ->ifString() ->then(static fn($value): array => [$value]) @@ -49,13 +49,13 @@ ->min(-1) ->end() ->arrayNode('pattern') - ->example('*.twig') + ->example('**/*.twig') ->info('Pattern of file names to parse with Twig parser.') ->beforeNormalization() ->ifString() ->then(static fn($value): array => [$value]) ->end() - ->defaultValue(['*.twig']) + ->defaultValue(['/^.+\.(sql\.twig|dql\.twig)$/i']) ->prototype('scalar')->end() ->end() ->arrayNode('globals') diff --git a/src/RunOpenCode/Component/Query/src/Parser/ContextAwareVariables.php b/src/RunOpenCode/Component/Query/src/Parser/ContextAwareVariables.php index 87ca74f..df2492e 100644 --- a/src/RunOpenCode/Component/Query/src/Parser/ContextAwareVariables.php +++ b/src/RunOpenCode/Component/Query/src/Parser/ContextAwareVariables.php @@ -46,9 +46,9 @@ /** * Create frozen, context aware variable bag. * - * @param \RunOpenCode\Component\Query\Contract\Context\ContextInterface $context Execution context. - * @param VariablesInterface|null $variables Variables to use for query/statement parsing. - * @param ParametersInterface|null $parameters Parameters to use for query/statement parsing. + * @param \RunOpenCode\Component\Query\Contract\Context\ContextInterface $context Execution context. + * @param VariablesInterface|null $variables Variables to use for query/statement parsing. + * @param ParametersInterface|null $parameters Parameters to use for query/statement parsing. */ public function __construct( public ContextInterface $context, @@ -60,7 +60,7 @@ public function __construct( $this->parser = $variables?->parser; $this->bag = \array_merge( $params, - $variables instanceof \RunOpenCode\Component\Query\Contract\Parser\VariablesInterface ? \iterator_to_array($variables) : [], + $variables instanceof VariablesInterface ? \iterator_to_array($variables) : [], [ 'variables' => $variables, 'parameters' => $parameters, diff --git a/src/RunOpenCode/Component/Query/src/Parser/Variables.php b/src/RunOpenCode/Component/Query/src/Parser/Variables.php index ad0f2d8..2eb81c6 100644 --- a/src/RunOpenCode/Component/Query/src/Parser/Variables.php +++ b/src/RunOpenCode/Component/Query/src/Parser/Variables.php @@ -56,6 +56,14 @@ public static function void(): self return new self(VoidParser::NAME); } + /** + * Create new variable bag for file parser. + */ + public static function file(): self + { + return new self(FileParser::NAME); + } + /** * Create new variables bag for twig parser. * diff --git a/src/RunOpenCode/Component/Query/tests/Functions/ToRegexTest.php b/src/RunOpenCode/Component/Query/tests/Functions/ToRegexTest.php new file mode 100644 index 0000000..7320cdc --- /dev/null +++ b/src/RunOpenCode/Component/Query/tests/Functions/ToRegexTest.php @@ -0,0 +1,43 @@ +assertSame($expected ? 1 : 0, \preg_match(to_regex($glob), $path)); + } + + /** + * @return iterable + */ + public static function get_data_for_glob_matches(): iterable + { + yield '*.twig, @foo/bar.sql.twig' => ['*.twig', '@foo/bar.sql.twig', false]; + yield '*.twig, foo.sql.twig' => ['*.twig', 'foo.sql.twig', true]; + yield '**/*.twig, @foo/bar.sql.twig' => ['**/*.twig', '@foo/bar.sql.twig', true]; + } + + /** + * @see https://github.com/symfony/symfony/issues/62737 + */ + #[Test] + public function monitor_fix(): void + { + $this->assertDoesNotMatchRegularExpression(to_regex('**/*.twig'), 'foo.sql.twig'); + } +}