From 2389210625d91213d105494ce198aa216f6f41ff Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:06:28 -0300 Subject: [PATCH 1/3] Translate into Brazilian Portuguese (#293) --- docs/pt-BR/testing.md | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/pt-BR/testing.md diff --git a/docs/pt-BR/testing.md b/docs/pt-BR/testing.md new file mode 100644 index 00000000..7d20dbe5 --- /dev/null +++ b/docs/pt-BR/testing.md @@ -0,0 +1,51 @@ +# Testes + +## Ações do Github + +Todos os nossos pacotes possuem ações do github por padrão, então você pode testar sua [contribuição](https://github.com/yiisoft/db-sqlite/blob/master/.github/CONTRIBUTING.md) na nuvem. + +> Observação: recomendamos a solicitação pull no modo rascunho até que todos os testes sejam aprovados. + +## Teste de unidade + +O pacote é testado com [PHPUnit](https://phpunit.de/). + +```shell +vendor/bin/phpunit +``` + +### Teste de mutação + +Os testes do pacote são verificados com a estrutura de mutação [Infection](https://infection.github.io/) e com +[plugin de análise estática de infecção](https://github.com/Roave/infection-static-analysis-plugin). Para executá-lo: + +```shell +./vendor/bin/roave-infection-static-analysis-plugin +``` + +## Análise estática + +O código é analisado estaticamente com [Psalm](https://psalm.dev/). Para executar a análise estática: + +```shell +./vendor/bin/psalm +``` + +## Reitor + +Use [Rector](https://github.com/rectorphp/rector) para fazer a base de código seguir algumas regras específicas ou +use a versão mais recente ou qualquer versão específica do PHP: + +```shell +./vendor/bin/rector +``` + +## Composer requer verificador + +Este pacote usa [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) para verificar se todas as dependências estão definidas corretamente em `composer.json`. + +Para executar o verificador, execute o seguinte comando: + +```shell +./vendor/bin/composer-require-checker +``` From 4a95c6bea300ed44088f787e9fa646111e747297 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 12 Apr 2024 18:44:49 +0700 Subject: [PATCH 2/3] Update test according to main PR (#289) Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 4 +-- rector.php | 5 +++- src/Builder/ExpressionBuilder.php | 16 ++++++++++ src/DQLQueryBuilder.php | 3 ++ src/SqlParser.php | 45 ++++++++++++++++++++++++++++ tests/CommandTest.php | 5 ++-- tests/Provider/SqlParserProvider.php | 30 +++++++++++++++++++ tests/QueryBuilderTest.php | 7 +++-- tests/SqlParserTest.php | 25 ++++++++++++++++ 9 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 src/Builder/ExpressionBuilder.php create mode 100644 src/SqlParser.php create mode 100644 tests/Provider/SqlParserProvider.php create mode 100644 tests/SqlParserTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 39a530e9..abb54123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # SQLite driver for Yii Database Change Log -## 1.2.1 under development +## 2.0.0 under development -- no changes in this release. +- Enh #289: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/rector.php b/rector.php index 6d4e4d49..8cbdabbd 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,10 @@ $rectorConfig->paths([ __DIR__ . '/src', - __DIR__ . '/tests', + /** + * Disabled ./tests directory due to different branches with main package when testing + */ + // __DIR__ . '/tests', ]); // register a single rule diff --git a/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php new file mode 100644 index 00000000..96ac22ee --- /dev/null +++ b/src/Builder/ExpressionBuilder.php @@ -0,0 +1,16 @@ + LikeConditionBuilder::class, InCondition::class => InConditionBuilder::class, JsonExpression::class => JsonExpressionBuilder::class, + Expression::class => ExpressionBuilder::class, ]); } } diff --git a/src/SqlParser.php b/src/SqlParser.php new file mode 100644 index 00000000..9698d6d6 --- /dev/null +++ b/src/SqlParser.php @@ -0,0 +1,45 @@ +length - 1; + + while ($this->position < $length) { + $pos = $this->position++; + + match ($this->sql[$pos]) { + ':' => ($word = $this->parseWord()) === '' + ? $this->skipChars(':') + : $result = ':' . $word, + '"', "'", '`' => $this->skipQuotedWithoutEscape($this->sql[$pos]), + '[' => $this->sql[$this->position] === '[' + ? $this->skipToAfterString(']]') + : $this->skipQuotedWithoutEscape(']'), + '-' => $this->sql[$this->position] === '-' + ? ++$this->position && $this->skipToAfterChar("\n") + : null, + '/' => $this->sql[$this->position] === '*' + ? ++$this->position && $this->skipToAfterString('*/') + : null, + default => null, + }; + + if ($result !== null) { + $position = $pos; + + return $result; + } + } + + return null; + } +} diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 7f3dbd4d..32486c27 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -465,9 +465,10 @@ public function testUpdate( array $columns, array|string $conditions, array $params, - string $expected + array $expectedValues, + int $expectedCount, ): void { - parent::testUpdate($table, $columns, $conditions, $params, $expected); + parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount); } /** diff --git a/tests/Provider/SqlParserProvider.php b/tests/Provider/SqlParserProvider.php new file mode 100644 index 00000000..77912c60 --- /dev/null +++ b/tests/Provider/SqlParserProvider.php @@ -0,0 +1,30 @@ + Date: Sat, 13 Apr 2024 15:02:56 +0700 Subject: [PATCH 3/3] Allow scalar values for `Query::select()` (#292) * Update tests according main PR * Apply Rector changes (CI) * Revert "Apply Rector changes (CI)" This reverts commit 132fef749da5ee8327a5d91101aa49286539fcaf. * Disable Rector for tests * Add type string to test --------- Co-authored-by: Tigrov Co-authored-by: Sergei Predvoditelev --- tests/QueryBuilderTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index a14c9116..42e51121 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -770,4 +770,10 @@ public function testJsonColumn() $qb->insert('json_table', ['json_col' => new JsonExpression(['a' => 1, 'b' => 2])]), ); } + + /** @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider::selectScalar */ + public function testSelectScalar(array|bool|float|int|string $columns, string $expected): void + { + parent::testSelectScalar($columns, $expected); + } }