Skip to content

Commit

Permalink
FilterProcessor: Fix predicate assembling for EXISTS and `NOT EXIST…
Browse files Browse the repository at this point in the history
…S` operators (#87)

fix #86
  • Loading branch information
raviks789 authored Jun 25, 2024
1 parent fe9903e commit e80f1b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
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))
);
}
}

0 comments on commit e80f1b7

Please sign in to comment.