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

api-platform / core / 13203378522

07 Feb 2025 03:56PM UTC coverage: 8.501% (+0.7%) from 7.837%
13203378522

push

github

soyuka
Merge 4.1

111 of 490 new or added lines in 51 files covered. (22.65%)

5590 existing lines in 163 files now uncovered.

13345 of 156987 relevant lines covered (8.5%)

22.88 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
        // ES v7
40
        if (class_exists(\Elasticsearch\ClientBuilder::class)) {
×
41
            $clientBuilder = \Elasticsearch\ClientBuilder::class;
×
42

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

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

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

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

75
        (new ElasticsearchClientPass())->process($containerBuilderProphecy->reveal());
×
76
    }
77

78
    public function testProcessWithoutConfiguration(): void
79
    {
NEW
80
        $clientBuilder = class_exists(\Elasticsearch\ClientBuilder::class)
×
NEW
81
            // ES v7
×
NEW
82
            ? \Elasticsearch\ClientBuilder::class
×
NEW
83
            // ES v8 and up
×
NEW
84
            : \Elastic\Elasticsearch\ClientBuilder::class;
×
85

86
        $clientDefinitionProphecy = $this->prophesize(Definition::class);
×
87
        $clientDefinitionProphecy->setFactory([$clientBuilder, 'build'])->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
88

89
        $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
×
90
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.enabled')->willReturn(true)->shouldBeCalled();
×
91
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.hosts')->willReturn([])->shouldBeCalled();
×
92
        $containerBuilderProphecy->has('logger')->willReturn(false)->shouldBeCalled();
×
93
        $containerBuilderProphecy->getDefinition('api_platform.elasticsearch.client')->willReturn($clientDefinitionProphecy->reveal())->shouldBeCalled();
×
94

95
        (new ElasticsearchClientPass())->process($containerBuilderProphecy->reveal());
×
96
    }
97

98
    public function testProcessWithElasticsearchDisabled(): void
99
    {
100
        $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
×
101
        $containerBuilderProphecy->getParameter('api_platform.elasticsearch.enabled')->willReturn(false)->shouldBeCalled();
×
102

103
        (new ElasticsearchClientPass())->process($containerBuilderProphecy->reveal());
×
104
    }
105
}
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