Skip to content

Commit

Permalink
FilterProcessorTest: Add test cases to assemble predicates for EXISTS…
Browse files Browse the repository at this point in the history
… and NOT EXISTS operators
  • Loading branch information
raviks789 committed Jun 24, 2024
1 parent b46bd66 commit ba1fcc4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 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 @@ -88,9 +90,25 @@ public function testNotInToSql()
['(foo NOT IN (?) OR foo IS NULL)' => $select],
FilterProcessor::assemblePredicate(new NotIn(['foo'], $select))
);
}

public function testExistsToSql()
{
$select = (new Select())->from('oof')->columns('*')->where(['foo = ?' => 'bar']);

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

public function testNotExistsToSql()
{
$select = (new Select())->from('oof')->columns('*')->where(['foo = ?' => 'bar']);

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

0 comments on commit ba1fcc4

Please sign in to comment.