-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FilterProcessor: Escape literal percent signs
fixes #71
- Loading branch information
Showing
2 changed files
with
45 additions
and
2 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,41 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Sql; | ||
|
||
use ipl\Sql\Compat\FilterProcessor; | ||
use ipl\Stdlib\Filter; | ||
|
||
class FilterProcessorTest extends TestCase | ||
{ | ||
public function testLikeToSql() | ||
{ | ||
$this->assertSame( | ||
['foo IS NOT NULL'], | ||
FilterProcessor::assemblePredicate(Filter::like('foo', '*')) | ||
); | ||
$this->assertSame( | ||
['foo LIKE ?' => '%bar%'], | ||
FilterProcessor::assemblePredicate(Filter::like('foo', '*bar*')) | ||
); | ||
$this->assertSame( | ||
['foo LIKE ?' => '%\\%%'], | ||
FilterProcessor::assemblePredicate(Filter::like('foo', '*%*')) | ||
); | ||
} | ||
|
||
public function testUnlikeToSql() | ||
{ | ||
$this->assertSame( | ||
['foo IS NULL'], | ||
FilterProcessor::assemblePredicate(Filter::unlike('foo', '*')) | ||
); | ||
$this->assertSame( | ||
['(foo NOT LIKE ? OR foo IS NULL)' => '%bar%'], | ||
FilterProcessor::assemblePredicate(Filter::unlike('foo', '*bar*')) | ||
); | ||
$this->assertSame( | ||
['(foo NOT LIKE ? OR foo IS NULL)' => '%\\%%'], | ||
FilterProcessor::assemblePredicate(Filter::unlike('foo', '*%*')) | ||
); | ||
} | ||
} |