-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into allow_scalars
- Loading branch information
Showing
9 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Builder; | ||
|
||
use Yiisoft\Db\Expression\AbstractExpressionBuilder; | ||
use Yiisoft\Db\Sqlite\SqlParser; | ||
|
||
final class ExpressionBuilder extends AbstractExpressionBuilder | ||
{ | ||
protected function createSqlParser(string $sql): SqlParser | ||
{ | ||
return new SqlParser($sql); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite; | ||
|
||
use Yiisoft\Db\Syntax\AbstractSqlParser; | ||
|
||
final class SqlParser extends AbstractSqlParser | ||
{ | ||
public function getNextPlaceholder(int|null &$position = null): string|null | ||
{ | ||
$result = null; | ||
$length = $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Tests\Provider; | ||
|
||
class SqlParserProvider extends \Yiisoft\Db\Tests\Provider\SqlParserProvider | ||
{ | ||
public static function getNextPlaceholder(): array | ||
{ | ||
return [ | ||
...parent::getNextPlaceholder(), | ||
[ | ||
'`:field` = :name AND age = :age', | ||
':name', | ||
11, | ||
], | ||
[ | ||
'[:field] = :name AND age = :age', | ||
':name', | ||
11, | ||
], | ||
[ | ||
'[[:field]] = :name AND age = :age', | ||
':name', | ||
13, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Tests; | ||
|
||
use Yiisoft\Db\Sqlite\SqlParser; | ||
use Yiisoft\Db\Tests\AbstractSqlParserTest; | ||
|
||
/** | ||
* @group sqlite | ||
*/ | ||
final class SqlParserTest extends AbstractSqlParserTest | ||
{ | ||
protected function createSqlParser(string $sql): SqlParser | ||
{ | ||
return new SqlParser($sql); | ||
} | ||
|
||
/** @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\SqlParserProvider::getNextPlaceholder */ | ||
public function testGetNextPlaceholder(string $sql, string|null $expectedPlaceholder, int|null $expectedPosition): void | ||
{ | ||
parent::testGetNextPlaceholder($sql, $expectedPlaceholder, $expectedPosition); | ||
} | ||
} |