Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test according to main PR #255

Merged
merged 11 commits into from
Apr 12, 2024
5 changes: 4 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
/**
* Disabled ./tests directory due to different branches with main package when testing
*/
// __DIR__ . '/tests',
vjik marked this conversation as resolved.
Show resolved Hide resolved
]);

// register a single rule
Expand Down
16 changes: 16 additions & 0 deletions src/Builder/ExpressionBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Oracle\Builder;

use Yiisoft\Db\Expression\AbstractExpressionBuilder;
use Yiisoft\Db\Oracle\SqlParser;

final class ExpressionBuilder extends AbstractExpressionBuilder
{
protected function createSqlParser(string $sql): SqlParser
{
return new SqlParser($sql);
}
}
1 change: 1 addition & 0 deletions src/ColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function dbTypecast(mixed $value): mixed
}

if (is_string($value)) {
/** @var non-empty-string $placeholder */
$placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName()));
return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]);
}
Expand Down
3 changes: 3 additions & 0 deletions src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Yiisoft\Db\Oracle;

use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Oracle\Builder\ExpressionBuilder;
use Yiisoft\Db\Oracle\Builder\InConditionBuilder;
use Yiisoft\Db\Oracle\Builder\LikeConditionBuilder;
use Yiisoft\Db\Query\Query;
Expand Down Expand Up @@ -87,6 +89,7 @@ protected function defaultExpressionBuilders(): array
[
InCondition::class => InConditionBuilder::class,
LikeCondition::class => LikeConditionBuilder::class,
Expression::class => ExpressionBuilder::class,
],
);
}
Expand Down
64 changes: 64 additions & 0 deletions src/SqlParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Oracle;

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->skipToAfterChar('"'),
"'" => $this->skipQuotedWithoutEscape($this->sql[$pos]),
'q', 'Q' => $this->sql[$this->position] === "'"
? $this->skipQuotedWithQ()
: null,
'-' => $this->sql[$this->position] === '-'
? ++$this->position && $this->skipToAfterChar("\n")

Check warning on line 29 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "Increment": --- Original +++ New @@ @@ '"' => $this->skipToAfterChar('"'), "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), 'q', 'Q' => $this->sql[$this->position] === "'" ? $this->skipQuotedWithQ() : null, - '-' => $this->sql[$this->position] === '-' ? ++$this->position && $this->skipToAfterChar("\n") : null, + '-' => $this->sql[$this->position] === '-' ? --$this->position && $this->skipToAfterChar("\n") : null, '/' => $this->sql[$this->position] === '*' ? ++$this->position && $this->skipToAfterString('*/') : null, default => null, };

Check warning on line 29 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndNegation": --- Original +++ New @@ @@ '"' => $this->skipToAfterChar('"'), "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), 'q', 'Q' => $this->sql[$this->position] === "'" ? $this->skipQuotedWithQ() : null, - '-' => $this->sql[$this->position] === '-' ? ++$this->position && $this->skipToAfterChar("\n") : null, + '-' => $this->sql[$this->position] === '-' ? !(++$this->position && $this->skipToAfterChar("\n")) : null, '/' => $this->sql[$this->position] === '*' ? ++$this->position && $this->skipToAfterString('*/') : null, default => null, };

Check warning on line 29 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ '"' => $this->skipToAfterChar('"'), "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), 'q', 'Q' => $this->sql[$this->position] === "'" ? $this->skipQuotedWithQ() : null, - '-' => $this->sql[$this->position] === '-' ? ++$this->position && $this->skipToAfterChar("\n") : null, + '-' => $this->sql[$this->position] === '-' ? ++$this->position && !$this->skipToAfterChar("\n") : null, '/' => $this->sql[$this->position] === '*' ? ++$this->position && $this->skipToAfterString('*/') : null, default => null, };
: null,
'/' => $this->sql[$this->position] === '*'
? ++$this->position && $this->skipToAfterString('*/')

Check warning on line 32 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "Increment": --- Original +++ New @@ @@ "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), 'q', 'Q' => $this->sql[$this->position] === "'" ? $this->skipQuotedWithQ() : null, '-' => $this->sql[$this->position] === '-' ? ++$this->position && $this->skipToAfterChar("\n") : null, - '/' => $this->sql[$this->position] === '*' ? ++$this->position && $this->skipToAfterString('*/') : null, + '/' => $this->sql[$this->position] === '*' ? --$this->position && $this->skipToAfterString('*/') : null, default => null, }; if ($result !== null) {

Check warning on line 32 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndNegation": --- Original +++ New @@ @@ "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), 'q', 'Q' => $this->sql[$this->position] === "'" ? $this->skipQuotedWithQ() : null, '-' => $this->sql[$this->position] === '-' ? ++$this->position && $this->skipToAfterChar("\n") : null, - '/' => $this->sql[$this->position] === '*' ? ++$this->position && $this->skipToAfterString('*/') : null, + '/' => $this->sql[$this->position] === '*' ? !(++$this->position && $this->skipToAfterString('*/')) : null, default => null, }; if ($result !== null) {

Check warning on line 32 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), 'q', 'Q' => $this->sql[$this->position] === "'" ? $this->skipQuotedWithQ() : null, '-' => $this->sql[$this->position] === '-' ? ++$this->position && $this->skipToAfterChar("\n") : null, - '/' => $this->sql[$this->position] === '*' ? ++$this->position && $this->skipToAfterString('*/') : null, + '/' => $this->sql[$this->position] === '*' ? ++$this->position && !$this->skipToAfterString('*/') : null, default => null, }; if ($result !== null) {
: null,
default => null,
};

if ($result !== null) {
$position = $pos;

return $result;
}
}

return null;
}

/**
* Skips quoted string with Q-operator.
*/
private function skipQuotedWithQ(): void
{
$endChar = match ($this->sql[++$this->position]) {

Check warning on line 52 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ { $endChar = match ($this->sql[++$this->position]) { '[' => ']', - '<' => '>', '{' => '}', '(' => ')', default => $this->sql[$this->position],

Check warning on line 52 in src/SqlParser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ $endChar = match ($this->sql[++$this->position]) { '[' => ']', '<' => '>', - '{' => '}', '(' => ')', default => $this->sql[$this->position], };
'[' => ']',
'<' => '>',
'{' => '}',
'(' => ')',
default => $this->sql[$this->position],
};

++$this->position;

$this->skipToAfterString("$endChar'");
}
}
5 changes: 3 additions & 2 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,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);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions tests/Provider/SqlParserProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Oracle\Tests\Provider;

class SqlParserProvider extends \Yiisoft\Db\Tests\Provider\SqlParserProvider
{
public static function getNextPlaceholder(): array
{
return [
...parent::getNextPlaceholder(),
[
"name = q'':name'' AND age = :age",
':age',
28,
],
[
"name = Q'':name'' AND age = :age",
':age',
28,
],
[
"name = Q'[:name]' AND age = :age",
':age',
28,
],
[
"name = Q'!':name'!' AND age = :age",
':age',
30,
],
];
}
}
7 changes: 4 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,11 @@ public function testUpdate(
string $table,
array $columns,
array|string $condition,
string $expectedSQL,
array $expectedParams
array $params,
string $expectedSql,
array $expectedParams,
): void {
parent::testUpdate($table, $columns, $condition, $expectedSQL, $expectedParams);
parent::testUpdate($table, $columns, $condition, $params, $expectedSql, $expectedParams);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/SqlParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Oracle\Tests;

use Yiisoft\Db\Oracle\SqlParser;
use Yiisoft\Db\Tests\AbstractSqlParserTest;

/**
* @group oracle
*/
final class SqlParserTest extends AbstractSqlParserTest
{
protected function createSqlParser(string $sql): SqlParser
{
return new SqlParser($sql);
}

/** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\SqlParserProvider::getNextPlaceholder */
public function testGetNextPlaceholder(string $sql, string|null $expectedPlaceholder, int|null $expectedPosition): void
{
parent::testGetNextPlaceholder($sql, $expectedPlaceholder, $expectedPosition);
}
}
Loading