Skip to content

Commit f57e2ad

Browse files
committed
add some missing cases
1 parent 2273e04 commit f57e2ad

1 file changed

Lines changed: 123 additions & 10 deletions

File tree

tests/RelationFilterTest.php

Lines changed: 123 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
* a) Number of conditions: multiple
2020
* b) Logical Operators: AND, OR, NOT(AND), NOT(OR)
2121
* c) Number of relations: single
22-
* d) Columns: same
22+
* d) Columns: same, different
2323
* e) Operators: same
2424
* f) Comparisons: affirmation, negation
2525
* e) Operators: different
26-
* d) Columns: different
27-
* e) Operators: same, different
2826
* c) Number of relations: multiple
2927
* e) Operators: same, different
3028
* f) Comparisons: affirmation, negation
@@ -652,12 +650,12 @@ public function testAndChainTargetingASingleRelationButDifferentColumnsWithDiffe
652650
/**
653651
* Search for offices where Donald works as accountant
654652
*
655-
* @equivalenceClass a:multiple, b:AND, c:single, d:different, e:same
653+
* @equivalenceClass a:multiple, b:AND, c:single, d:different, e:same, f:affirmation
656654
* @dataProvider databases
657655
*
658656
* @param Connection $db
659657
*/
660-
public function testAndChainTargetingASingleRelationButDifferentColumnsWithTheSameOperator(Connection $db)
658+
public function testAndChainTargetingASingleRelationButDifferentColumnsWithTheSameAffirmativeOperator(Connection $db)
661659
{
662660
$this->createOfficesAndEmployees($db);
663661

@@ -689,6 +687,55 @@ public function testAndChainTargetingASingleRelationButDifferentColumnsWithTheSa
689687
$this->assertSame(2, count($results), $sql);
690688
}
691689

690+
/**
691+
* Search for offices where Donald doesn't work as accountant
692+
*
693+
* @equivalenceClass a:multiple, b:AND, c:single, d:different, e:same, f:negation
694+
* @dataProvider databases
695+
*
696+
* @param Connection $db
697+
*/
698+
public function testAndChainTargetingASingleRelationButDifferentColumnsWithTheSameNegativeOperator(Connection $db)
699+
{
700+
$this->createOfficesAndEmployees($db);
701+
702+
$offices = $db->prepexec(
703+
'SELECT office.city FROM office'
704+
. ' WHERE office.id NOT IN ('
705+
. ' SELECT office.id FROM office'
706+
. ' LEFT JOIN employee e ON e.office_id = office.id'
707+
. ' WHERE e.name = ? AND e.role = ?'
708+
. ' GROUP BY office.id'
709+
. ' )'
710+
. ' ORDER BY office.id',
711+
['Donald', 'Accountant']
712+
)->fetchAll();
713+
714+
$this->assertSame('Amsterdam', $offices[0]['city'] ?? 'not found');
715+
$this->assertSame('New York', $offices[1]['city'] ?? 'not found');
716+
$this->assertSame('Cuxhaven', $offices[2]['city'] ?? 'not found');
717+
$this->assertSame('Sydney', $offices[3]['city'] ?? 'not found');
718+
$this->assertSame('Baghdad', $offices[4]['city'] ?? 'not found');
719+
$this->assertSame(5, count($offices));
720+
721+
$offices = Office::on($db)
722+
->columns(['office.city'])
723+
->orderBy('office.id')
724+
->filter(Filter::all(
725+
Filter::unequal('employee.name', 'Donald'),
726+
Filter::unequal('employee.role', 'Accountant')
727+
));
728+
$results = iterator_to_array($offices);
729+
$sql = $this->getSql($offices);
730+
731+
$this->assertSame('Amsterdam', $results[0]['city'] ?? 'not found', $sql);
732+
$this->assertSame('New York', $results[1]['city'] ?? 'not found', $sql);
733+
$this->assertSame('Cuxhaven', $results[2]['city'] ?? 'not found', $sql);
734+
$this->assertSame('Sydney', $results[3]['city'] ?? 'not found', $sql);
735+
$this->assertSame('Baghdad', $results[4]['city'] ?? 'not found', $sql);
736+
$this->assertSame(5, count($results), $sql);
737+
}
738+
692739
/**
693740
* Search for offices where Donald works or someone else not as accountant
694741
*
@@ -742,12 +789,12 @@ public function testOrChainTargetingASingleRelationButDifferentColumnsWithDiffer
742789
/**
743790
* Search for offices where either Donald works or any other assistant
744791
*
745-
* @equivalenceClass a:multiple, b:OR, c:single, d:different, e:same
792+
* @equivalenceClass a:multiple, b:OR, c:single, d:different, e:same, f:affirmation
746793
* @dataProvider databases
747794
*
748795
* @param Connection $db
749796
*/
750-
public function testOrChainTargetingASingleRelationButDifferentColumnsWithTheSameOperator(Connection $db)
797+
public function testOrChainTargetingASingleRelationButDifferentColumnsWithTheSameAffirmativeOperator(Connection $db)
751798
{
752799
$this->createOfficesAndEmployees($db);
753800

@@ -785,6 +832,58 @@ public function testOrChainTargetingASingleRelationButDifferentColumnsWithTheSam
785832
$this->assertSame(5, count($results), $sql);
786833
}
787834

835+
/**
836+
* Search for offices where either Donald doesn't work or no-one as manager
837+
*
838+
* @equivalenceClass a:multiple, b:OR, c:single, d:different, e:same, f:negation
839+
* @dataProvider databases
840+
*
841+
* @param Connection $db
842+
*/
843+
public function testOrChainTargetingASingleRelationButDifferentColumnsWithTheSameNegativeOperator(Connection $db)
844+
{
845+
$this->createOfficesAndEmployees($db);
846+
847+
$offices = $db->prepexec(
848+
'SELECT office.city FROM office'
849+
. ' WHERE office.id NOT IN ('
850+
. ' SELECT office.id FROM office'
851+
. ' LEFT JOIN employee e ON e.office_id = office.id'
852+
. ' WHERE e.name = ?'
853+
. ' GROUP BY office.id'
854+
. ' ) OR office.id NOT IN ('
855+
. ' SELECT office.id FROM office'
856+
. ' LEFT JOIN employee e ON e.office_id = office.id'
857+
. ' WHERE e.role = ?'
858+
. ' GROUP BY office.id'
859+
. ' )'
860+
. ' ORDER BY office.id',
861+
['Donald', 'Manager']
862+
)->fetchAll();
863+
864+
$this->assertSame('Amsterdam', $offices[0]['city'] ?? 'not found');
865+
$this->assertSame('New York', $offices[1]['city'] ?? 'not found');
866+
$this->assertSame('Cuxhaven', $offices[2]['city'] ?? 'not found');
867+
$this->assertSame('Sydney', $offices[3]['city'] ?? 'not found');
868+
$this->assertSame(4, count($offices));
869+
870+
$offices = Office::on($db)
871+
->columns(['office.city'])
872+
->orderBy('office.id')
873+
->filter(Filter::any(
874+
Filter::unequal('employee.name', 'Donald'),
875+
Filter::unequal('employee.role', 'Manager')
876+
));
877+
$results = iterator_to_array($offices);
878+
$sql = $this->getSql($offices);
879+
880+
$this->assertSame('Amsterdam', $results[0]['city'] ?? 'not found', $sql);
881+
$this->assertSame('New York', $results[1]['city'] ?? 'not found', $sql);
882+
$this->assertSame('Cuxhaven', $results[2]['city'] ?? 'not found', $sql);
883+
$this->assertSame('Sydney', $results[3]['city'] ?? 'not found', $sql);
884+
$this->assertSame(4, count($results), $sql);
885+
}
886+
788887
/**
789888
* Search for offices where not just Huey works or only as a manager
790889
*
@@ -836,14 +935,15 @@ public function testNotChainTargetingASingleRelationButDifferentColumnsWithDiffe
836935
/**
837936
* Search for offices where not just Donald works or not as manager
838937
*
839-
* @equivalenceClass a:multiple, b:NOT(AND), c:single, d:different, e:same
938+
* @equivalenceClass a:multiple, b:NOT(AND), c:single, d:different, e:same, f:affirmation
840939
* @dataProvider databases
841940
* @todo Finds Cuxhaven instead of Baghdad. Not wrong, actually. Why does monitoring behave differently?
842941
*
843942
* @param Connection $db
844943
*/
845-
public function testNotChainTargetingASingleRelationButDifferentColumnsWithTheSameOperator(Connection $db)
846-
{
944+
public function testNotChainTargetingASingleRelationButDifferentColumnsWithTheSameAffirmativeOperator(
945+
Connection $db
946+
) {
847947
$this->createOfficesAndEmployees($db);
848948

849949
$offices = $db->prepexec(
@@ -882,6 +982,19 @@ public function testNotChainTargetingASingleRelationButDifferentColumnsWithTheSa
882982
$this->assertSame(6, count($results), $sql);
883983
}
884984

985+
/**
986+
* Search for offices where ...
987+
*
988+
* @equivalenceClass a:multiple, b:NOT(AND), c:single, d:different, e:same, f:negation
989+
* @dataProvider databases
990+
*
991+
* @param Connection $db
992+
*/
993+
public function testNotChainTargetingASingleRelationButDifferentColumnsWithTheSameNegativeOperator(Connection $db)
994+
{
995+
$this->markTestIncomplete('This test has not been implemented yet.');
996+
}
997+
885998
/**
886999
* Search for offices where Donald works in the accounting department
8871000
*

0 commit comments

Comments
 (0)