Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Mar 12, 2024
1 parent 00a0cb9 commit 2273e04
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions tests/RelationFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* e) Operators: same, different
* f) Comparisons: affirmation, negation
*
* If a test covers such a case, it is marked with the corresponding variables.
*
* The tests rely on a few assumptions which are the same for all of them:
* - All filters target a to-many relation
* - The ORM only differs between negative and affirmative filters, hence why only equal and unequal filters are used
Expand Down Expand Up @@ -1320,48 +1318,6 @@ public function testNotChainTargetingMultipleRelationsWithDifferentOperators(Con
$this->assertSame(5, count($results), $sql);
}

/**
* Test whether an unequal, that targets a to-many relation to which a link can only be established through an
* optional other relation, is built by the ORM in a way that coincidental matches are ignored
*
* This will fail if the ORM generates a NOT IN which uses a subquery that produces NULL values.
*
* @dataProvider databases
*/
public function testUnequalTargetingAnOptionalToManyRelationIgnoresFalsePositives(Connection $db)
{
$db->insert('office', ['id' => 1, 'city' => 'London']);
$db->insert('department', ['id' => 1, 'name' => 'Accounting']);
$db->insert('department', ['id' => 2, 'name' => 'Kitchen']);
$db->insert('employee', ['id' => 1, 'department_id' => 1, 'name' => 'Minnie', 'role' => 'CEO']); // remote
$db->insert(
'employee',
['id' => 2, 'department_id' => 2, 'office_id' => 1, 'name' => 'Goofy', 'role' => 'Developer']
);

// This POC uses inner joins to achieve the desired result
$offices = $db->prepexec(
'SELECT office.city FROM office'
. ' INNER JOIN employee e on e.office_id = office.id'
. ' INNER JOIN department d on e.department_id = d.id'
. ' WHERE d.name != ?'
. ' GROUP BY office.id'
. ' ORDER BY office.id',
['Accounting']
)->fetchAll();

$this->assertSame('London', $offices[0]['city'] ?? 'not found');

// The ORM will use a NOT IN and needs to ignore false positives explicitly
$offices = Office::on($db)
->columns(['office.city'])
->orderBy('office.id')
->filter(Filter::unequal('employee.department.name', 'Accounting'));
$results = iterator_to_array($offices);

$this->assertSame('London', $results[0]['city'] ?? 'not found', $this->getSql($offices));
}

/**
* Create a definite set of permutations with employees and offices
*
Expand Down

0 comments on commit 2273e04

Please sign in to comment.