Code Duplication    Length = 15-17 lines in 4 locations

tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php 4 locations

@@ 455-471 (lines=17) @@
452
        $this->assertNull($this->_em->getRepository(CmsGroup::class)->findOneById($this->groupId2));
453
    }
454
455
    public function testToOneFilter()
456
    {
457
        //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
458
        $this->loadFixtureData();
459
460
        $query = $this->_em->createQuery('select ux, ua from Doctrine\Tests\Models\CMS\CmsUser ux JOIN ux.address ua');
461
462
        // We get two users before enabling the filter
463
        $this->assertEquals(2, count($query->getResult()));
464
465
        $conf = $this->_em->getConfiguration();
466
        $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter");
467
        $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", DBALType::STRING);
468
469
        // We get one user after enabling the filter
470
        $this->assertEquals(1, count($query->getResult()));
471
    }
472
473
    public function testManyToManyFilter()
474
    {
@@ 473-488 (lines=16) @@
470
        $this->assertEquals(1, count($query->getResult()));
471
    }
472
473
    public function testManyToManyFilter()
474
    {
475
        $this->loadFixtureData();
476
        $query = $this->_em->createQuery('select ux, ug from Doctrine\Tests\Models\CMS\CmsUser ux JOIN ux.groups ug');
477
478
        // We get two users before enabling the filter
479
        $this->assertEquals(2, count($query->getResult()));
480
481
        $conf = $this->_em->getConfiguration();
482
        $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter");
483
        $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING);
484
485
        // We get one user after enabling the filter
486
        $this->assertEquals(1, count($query->getResult()));
487
488
    }
489
490
    public function testWhereFilter()
491
    {
@@ 490-504 (lines=15) @@
487
488
    }
489
490
    public function testWhereFilter()
491
    {
492
        $this->loadFixtureData();
493
        $query = $this->_em->createQuery('select ug from Doctrine\Tests\Models\CMS\CmsGroup ug WHERE 1=1');
494
495
        // We get two users before enabling the filter
496
        $this->assertEquals(2, count($query->getResult()));
497
498
        $conf = $this->_em->getConfiguration();
499
        $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter");
500
        $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING);
501
502
        // We get one user after enabling the filter
503
        $this->assertEquals(1, count($query->getResult()));
504
    }
505
506
    public function testWhereOrFilter()
507
    {
@@ 506-520 (lines=15) @@
503
        $this->assertEquals(1, count($query->getResult()));
504
    }
505
506
    public function testWhereOrFilter()
507
    {
508
        $this->loadFixtureData();
509
        $query = $this->_em->createQuery('select ug from Doctrine\Tests\Models\CMS\CmsGroup ug WHERE 1=1 OR 1=1');
510
511
        // We get two users before enabling the filter
512
        $this->assertEquals(2, count($query->getResult()));
513
514
        $conf = $this->_em->getConfiguration();
515
        $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter");
516
        $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING);
517
518
        // We get one user after enabling the filter
519
        $this->assertEquals(1, count($query->getResult()));
520
    }
521
522
523
    private function loadLazyFixtureData()