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

FilterProcessor: Fix predicate assembling for EXISTS and NOT EXISTS operators #87

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -255,31 +255,11 @@ parameters:
count: 1
path: src/Connection.php

-
message: "#^Parameter \\#1 \\$mode of method PDOStatement\\:\\:setFetchMode\\(\\) expects int, mixed given\\.$#"
count: 1
path: src/Connection.php

-
message: "#^Parameter \\#1 \\$object_or_class of function method_exists expects object\\|string, PDO\\|null given\\.$#"
count: 1
path: src/Connection.php

-
message: "#^Parameter \\#2 \\$className of method PDOStatement\\:\\:setFetchMode\\(\\) expects int\\|object\\|string, mixed given\\.$#"
count: 1
path: src/Connection.php

-
message: "#^Parameter \\#2 \\$values of method ipl\\\\Sql\\\\Connection\\:\\:prepexec\\(\\) expects array\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Connection.php

-
message: "#^Parameter \\#2 \\$values of method ipl\\\\Sql\\\\Connection\\:\\:yieldPairs\\(\\) expects array\\|null, mixed given\\.$#"
count: 1
path: src/Connection.php

-
message: "#^Property ipl\\\\Sql\\\\Connection\\:\\:\\$adapter \\(ipl\\\\Sql\\\\Contract\\\\Adapter\\) does not accept object\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/Compat/FilterProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function assemblePredicate(Filter\Condition $filter)
$column = $filter->getColumn();
$expression = $filter->getValue();

if (is_array($expression) || $expression instanceof Select) {
if (! empty($column) && (is_array($expression) || $expression instanceof Select)) {
$nullVerification = true;
if (is_array($column)) {
if (count($column) === 1) {
Expand Down
22 changes: 22 additions & 0 deletions tests/FilterProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace ipl\Tests\Sql;

use ipl\Sql\Compat\FilterProcessor;
use ipl\Sql\Filter\Exists;
use ipl\Sql\Filter\In;
use ipl\Sql\Filter\NotExists;
use ipl\Sql\Filter\NotIn;
use ipl\Sql\Select;
use ipl\Stdlib\Filter;
Expand Down Expand Up @@ -93,4 +95,24 @@ public function testNotInToSql()
FilterProcessor::assemblePredicate(new NotIn(['foo', 'bar'], $select))
);
}

public function testExistsToSql()
{
$select = (new Select())->from('oof')->columns('*');

$this->assertSame(
[' EXISTS ?' => $select],
FilterProcessor::assemblePredicate(new Exists($select))
);
}

public function testNotExistsToSql()
{
$select = (new Select())->from('oof')->columns('*');

$this->assertSame(
[' NOT EXISTS ?' => $select],
FilterProcessor::assemblePredicate(new NotExists($select))
);
}
}
Loading