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

api-platform / core / 10323369133

09 Aug 2024 05:39PM UTC coverage: 7.841%. Remained the same
10323369133

push

github

web-flow
Merge 3.4 (#6507)

* tests: remove output suffix after reverting

* cs: remove unnecessary comments (#6408)

* fix(elasticsearch): change normalize return type to compatible with other normalizers (#6493)

* style: various cs fixes (#6504)

* cs: fixes

* chore: phpstan fixes

* style: cs fixes

---------

Co-authored-by: Takashi Kanemoto <4360663+ttskch@users.noreply.github.com>
Co-authored-by: Koen Pasman <118996061+Koenstell@users.noreply.github.com>

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

21 existing lines in 7 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

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

0.0
/tests/Symfony/Bundle/DependencyInjection/Compiler/ElasticsearchClientPassTest.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\Tests\Symfony\Bundle\DependencyInjection\Compiler;
15

16
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\ElasticsearchClientPass;
17
use PHPUnit\Framework\TestCase;
18
use Prophecy\Argument;
19
use Prophecy\PhpUnit\ProphecyTrait;
20
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Definition;
23
use Symfony\Component\DependencyInjection\Reference;
24

25
/**
26
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
27
 */
28
class ElasticsearchClientPassTest extends TestCase
29
{
30
    use ProphecyTrait;
31

32
    public function testConstruct(): void
33
    {
34
        self::assertInstanceOf(CompilerPassInterface::class, new ElasticsearchClientPass());
×
35
    }
36

37
    public function testProcess(): void
38
    {
39
        if (class_exists(\Elasticsearch\ClientBuilder::class)) {
×
40
            $clientBuilder = \Elasticsearch\ClientBuilder::class;
×
41

42
            $expectedArguments = [
×
43
                Argument::withEntry('hosts', ['http://localhost:9200']),
×
44
                Argument::withEntry('logger', Argument::type(Reference::class)),
×
45
                Argument::withEntry('tracer', Argument::type(Reference::class)),
×
46
                Argument::size(3),
×
47
            ];
×
48
        } else {
49
            $clientBuilder = \Elastic\Elasticsearch\ClientBuilder::class;
×
50

51
            $expectedArguments = [
×
52
                Argument::withEntry('hosts', ['http://localhost:9200']),
×
53
                Argument::withEntry('logger', Argument::type(Reference::class)),
×
54
                Argument::size(2),
×
55
            ];
×
56
        }
57

58
        $clientDefinitionProphecy = $this->prophesize(Definition::class);
×
UNCOV
59
        $clientDefinitionProphecy->setFactory([$clientBuilder, 'fromConfig'])->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
60
        $clientDefinitionProphecy->setArguments(
×
61
            Argument::allOf(
×
62
                Argument::withEntry(0, Argument::allOf(...$expectedArguments)),
×
63
                Argument::size(1)
×
64
            )
×
65
        )->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
66

67
        $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
×
68
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.enabled')->willReturn(true)->shouldBeCalled();
×
69
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.hosts')->willReturn(['http://localhost:9200'])->shouldBeCalled();
×
70
        $containerBuilderProphecy->has('logger')->willReturn(true)->shouldBeCalled();
×
71
        $containerBuilderProphecy->getDefinition('api_platform.elasticsearch.client')->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
72

73
        (new ElasticsearchClientPass())->process($containerBuilderProphecy->reveal());
×
74
    }
75

76
    public function testProcessWithoutConfiguration(): void
77
    {
78
        $clientBuilder = class_exists(\Elasticsearch\ClientBuilder::class) ? \Elasticsearch\ClientBuilder::class : \Elastic\Elasticsearch\ClientBuilder::class;
×
79

80
        $clientDefinitionProphecy = $this->prophesize(Definition::class);
×
UNCOV
81
        $clientDefinitionProphecy->setFactory([$clientBuilder, 'build'])->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
82

83
        $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
×
84
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.enabled')->willReturn(true)->shouldBeCalled();
×
85
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.hosts')->willReturn([])->shouldBeCalled();
×
86
        $containerBuilderProphecy->has('logger')->willReturn(false)->shouldBeCalled();
×
87
        $containerBuilderProphecy->getDefinition('api_platform.elasticsearch.client')->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
88

89
        (new ElasticsearchClientPass())->process($containerBuilderProphecy->reveal());
×
90
    }
91

92
    public function testProcessWithElasticsearchDisabled(): void
93
    {
94
        $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
×
95
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.enabled')->willReturn(false)->shouldBeCalled();
×
96

97
        (new ElasticsearchClientPass())->process($containerBuilderProphecy->reveal());
×
98
    }
99
}
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