testLoadQueryBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Tests\GBProd\ElasticaSpecificationBundle\DependencyInjection;
4
5
use Elastica\QueryBuilder;
6
use Elastica\QueryBuilder\Version\Latest;
7
use Elastica\QueryBuilder\Version\Version240;
8
use GBProd\ElasticaSpecificationBundle\DependencyInjection\ElasticaSpecificationExtension;
9
use GBProd\ElasticaSpecification\Handler;
10
use GBProd\ElasticaSpecification\Registry;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
14
/**
15
 * Tests for ElasticaSpecificationExtension
16
 *
17
 * @author gbprod <[email protected]>
18
 */
19
class ElasticaSpecificationExtensionTest extends TestCase
20
{
21
    private $extension;
22
    private $container;
23
24
    protected function setUp()
25
    {
26
        $this->extension = new ElasticaSpecificationExtension();
27
28
        $this->container = new ContainerBuilder();
29
        $this->container->registerExtension($this->extension);
30
    }
31
32
    public function testLoadHasServices()
33
    {
34
        $this->load();
35
36
        $this->assertTrue(
37
            $this->container->has('gbprod.elastica_specification_querybuilder')
38
        );
39
40
        $this->assertTrue(
41
            $this->container->has('gbprod.elastica_specification_registry')
42
        );
43
44
        $this->assertTrue(
45
            $this->container->has('gbprod.elastica_specification_handler')
46
        );
47
    }
48
49
    private function load(array $config = [])
50
    {
51
        $this->container->loadFromExtension($this->extension->getAlias(), $config);
52
        $this->container->compile();
53
    }
54
55
    public function testLoadQueryBuilder()
56
    {
57
        $this->load();
58
59
        $registry = $this->container->get('gbprod.elastica_specification_querybuilder');
60
61
        $this->assertInstanceOf(QueryBuilder::class, $registry);
62
    }
63
64
    public function testLoadRegistry()
65
    {
66
        $this->load();
67
68
        $registry = $this->container->get('gbprod.elastica_specification_registry');
69
70
        $this->assertInstanceOf(Registry::class, $registry);
71
    }
72
73
    public function testLoadHandler()
74
    {
75
        $this->load();
76
77
        $handler = $this->container->get('gbprod.elastica_specification_handler');
78
79
        $this->assertInstanceOf(Handler::class, $handler);
80
    }
81
82
    public function testLoadDsl()
83
    {
84
        $this->load();
85
86
        $dsl = $this->container->get('gbprod.elastica_specification_dsl');
87
88
        $this->assertInstanceOf(Latest::class, $dsl);
89
    }
90
91
    public function testLoadCustomizedDsl()
92
    {
93
        $this->load([
94
            'dsl_version' => 'Version240',
95
        ]);
96
97
        $dsl = $this->container->get('gbprod.elastica_specification_dsl');
98
99
        $this->assertInstanceOf(Version240::class, $dsl);
100
    }
101
}
102