Skip to content

Commit

Permalink
test: Add case for ipl\Orm\Compat\FilterProcessor
Browse files Browse the repository at this point in the history
refs #118
  • Loading branch information
nilmerg committed Sep 18, 2023
1 parent cbb42fb commit 36c44ed
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/FilterProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace ipl\Tests\Orm;

use ipl\Orm\Compat\FilterProcessor;
use ipl\Orm\Query;
use ipl\Stdlib\Filter;

class FilterProcessorTest extends \PHPUnit\Framework\TestCase
{
public function testUnequalDoesNotOverrideUnlike()
{
$query = new Query();
$query->setModel(new Car());
$query->setDb(new TestConnection());

$filter = Filter::all(
Filter::unequal('passenger.name', 'foo'),
Filter::unlike('passenger.gender', 'b*r')
);

FilterProcessor::apply($filter, $query);

$where = $query->getSelectBase()->getWhere();

$this->assertArrayHasKey(1, $where);
$this->assertArrayHasKey(0, $where[1]);
$this->assertArrayHasKey(1, $where[1][0]);
$this->assertArrayHasKey(0, $where[1][0][1]);
$this->assertArrayHasKey(1, $where[1][0][1][0]);
$this->assertArrayHasKey('(car.id NOT IN (?) OR car.id IS NULL)', $where[1][0][1][0][1]);
$this->assertSame(
['AND', [
['AND', [
['OR', [
['AND', [
['AND', [
'sub_passenger.name = ?' => 'foo'
]]
]]
]]
]]
]],
$where[1][0][1][0][1]['(car.id NOT IN (?) OR car.id IS NULL)']->getWhere()
);

$this->assertArrayHasKey(1, $where[1][0][1]);
$this->assertArrayHasKey(1, $where[1][0][1][1]);
$this->assertArrayHasKey('(car.id NOT IN (?) OR car.id IS NULL)', $where[1][0][1][1][1]);
$this->assertSame(
['AND', [
['AND', [
['OR', [
['AND', [
['AND', [
'sub_passenger.gender LIKE ?' => 'b%r'
]]
]]
]]
]]
]],
$where[1][0][1][1][1]['(car.id NOT IN (?) OR car.id IS NULL)']->getWhere()
);
}
}

0 comments on commit 36c44ed

Please sign in to comment.