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 @@ +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/Bundle/QueryBundle/config/services/middleware.php b/src/RunOpenCode/Bundle/QueryBundle/config/services/middleware.php index 7c856c7..5280602 100644 --- a/src/RunOpenCode/Bundle/QueryBundle/config/services/middleware.php +++ b/src/RunOpenCode/Bundle/QueryBundle/config/services/middleware.php @@ -51,7 +51,7 @@ ->tag('runopencode.query.middleware', [ 'alias' => 'slow', ]); - + $configurator ->set(ConvertMiddleware::class) ->arg('$registry', AdapterRegistry::class) 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/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, + )); } } 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'); + } +}