• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Test/DoctrineOrmFilterTestCase.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Test;
15

16
use ApiPlatform\Doctrine\Orm\Filter\FilterInterface;
17
use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator;
18
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
19
use Doctrine\ORM\EntityRepository;
20
use Doctrine\Persistence\ManagerRegistry;
21
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
22

23
/**
24
 * @internal
25
 *
26
 * @author Kévin Dunglas <dunglas@gmail.com>
27
 */
28
abstract class DoctrineOrmFilterTestCase extends KernelTestCase
29
{
30
    protected ManagerRegistry $managerRegistry;
31

32
    protected EntityRepository $repository;
33

34
    protected string $resourceClass = Dummy::class;
35

36
    protected const ALIAS = 'o';
37

38
    protected string $filterClass;
39

40
    protected function setUp(): void
41
    {
UNCOV
42
        self::bootKernel();
×
43

UNCOV
44
        $this->managerRegistry = self::$kernel->getContainer()->get('doctrine');
×
UNCOV
45
        $this->repository = $this->managerRegistry->getManagerForClass(Dummy::class)->getRepository(Dummy::class);
×
46
    }
47

48
    /**
49
     * @dataProvider provideApplyTestData
50
     */
51
    public function testApply(?array $properties, array $filterParameters, string $expectedDql, array $expectedParameters = null, callable $factory = null, string $resourceClass = null): void
52
    {
UNCOV
53
        $this->doTestApply($properties, $filterParameters, $expectedDql, $expectedParameters, $factory, $resourceClass);
×
54
    }
55

56
    protected function doTestApply(?array $properties, array $filterParameters, string $expectedDql, array $expectedParameters = null, callable $filterFactory = null, string $resourceClass = null): void
57
    {
UNCOV
58
        if (null === $filterFactory) {
×
UNCOV
59
            $filterFactory = fn (self $that, ManagerRegistry $managerRegistry, array $properties = null): FilterInterface => new ($this->filterClass)($managerRegistry, null, $properties);
×
60
        }
61

UNCOV
62
        $repository = $this->repository;
×
UNCOV
63
        if ($resourceClass) {
×
64
            /** @var EntityRepository $repository */
UNCOV
65
            $repository = $this->managerRegistry->getManagerForClass($resourceClass)->getRepository($resourceClass);
×
66
        }
UNCOV
67
        $resourceClass = $resourceClass ?: $this->resourceClass;
×
UNCOV
68
        $queryBuilder = $repository->createQueryBuilder(static::ALIAS);
×
UNCOV
69
        $filterCallable = $filterFactory($this, $this->managerRegistry, $properties);
×
UNCOV
70
        $filterCallable->apply($queryBuilder, new QueryNameGenerator(), $resourceClass, null, ['filters' => $filterParameters]);
×
71

UNCOV
72
        $this->assertSame($expectedDql, $queryBuilder->getQuery()->getDQL());
×
73

UNCOV
74
        if (null === $expectedParameters) {
×
UNCOV
75
            return;
×
76
        }
77

UNCOV
78
        foreach ($expectedParameters as $parameterName => $expectedParameterValue) {
×
UNCOV
79
            $queryParameter = $queryBuilder->getQuery()->getParameter($parameterName);
×
80

UNCOV
81
            $this->assertNotNull($queryParameter, sprintf('Expected query parameter "%s" to be set', $parameterName));
×
UNCOV
82
            $this->assertEquals($expectedParameterValue, $queryParameter->getValue(), sprintf('Expected query parameter "%s" to be "%s"', $parameterName, var_export($expectedParameterValue, true)));
×
83
        }
84
    }
85

86
    protected function buildFilter(array $properties = null)
87
    {
UNCOV
88
        return new $this->filterClass($this->managerRegistry, null, $properties);
×
89
    }
90

91
    abstract public static function provideApplyTestData(): array;
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc