Create data filter for Doctrine EntityManager

Code
<?php

use Doctrine\ORM\Query\Filter\SQLFilter;
use Doctrine\ORM\Mapping\ClassMetadata;
use PHPSnippets\Db\Entity\Test;

// create SQLFilter that works on every entity/table
// the filter works with SQL, not DQL
class FooFilter extends SQLFilter
{
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
    {
        return $targetTableAlias . '.name != \'test\'';
    }
}

// add new filter to config and name it "foo"
$entityManager->getConfiguration()
    ->addFilter('foo', 'FooFilter');

$repo = $entityManager->getRepository(Test::CLASS);

// get unfiltered data
echo 'All data:' . PHP_EOL;
$tests = $repo->findAll();
foreach ($tests as $test) {
    echo $test->id . ' ' .
        $test->name . PHP_EOL;
}

// enable the filter named foo
$entityManager->getFilters()->enable('foo');

// get filtered data
echo PHP_EOL . 'Filtered data:' . PHP_EOL;
$tests = $repo->findAll();
foreach ($tests as $test) {
    echo $test->id . ' ' .
        $test->name . PHP_EOL;
}
Result
All data:
1 foo
2 test
3 bar

Filtered data:
1 foo
3 bar
Used Versions
PHP 8.3, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8