Completed
Push — 3.1.x ( a865a3...b5e6ea )
by Karel
09:59
created

MappingToElasticaTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the FOSElasticaBundle project.
5
 *
6
 * (c) Tim Nagel <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace FOS\ElasticaBundle\Tests\Functional;
13
14
use Symfony\Bundle\FrameworkBundle\Client;
15
16
/**
17
 * @group functional
18
 */
19
class MappingToElasticaTest extends WebTestCase
20
{
21
    public function testResetIndexAddsMappings()
22
    {
23
        $client = $this->createClient(array('test_case' => 'Basic'));
24
        $resetter = $this->getResetter($client);
25
        $resetter->resetIndex('index');
26
27
        $type = $this->getType($client);
28
        $mapping = $type->getMapping();
29
30
        $this->assertNotEmpty($mapping, 'Mapping was populated');
31
32
        $type = $this->getType($client, 'type');
33
        $mapping = $type->getMapping();
34
        $this->assertEquals('parent', $mapping['type']['_parent']['type']);
35
36
        $parent = $this->getType($client, 'parent');
37
        $mapping = $parent->getMapping();
38
39
        $this->assertEquals('my_analyzer', $mapping['parent']['index_analyzer']);
40
        $this->assertEquals('whitespace', $mapping['parent']['search_analyzer']);
41
    }
42
43
    public function testResetType()
44
    {
45
        $client = $this->createClient(array('test_case' => 'Basic'));
46
        $resetter = $this->getResetter($client);
47
        $resetter->resetIndexType('index', 'type');
48
49
        $type = $this->getType($client);
50
        $mapping = $type->getMapping();
51
52
        $this->assertNotEmpty($mapping, 'Mapping was populated');
53
        $this->assertFalse($mapping['type']['date_detection']);
54
        $this->assertTrue($mapping['type']['numeric_detection']);
55
        $this->assertEquals(array('yyyy-MM-dd'), $mapping['type']['dynamic_date_formats']);
56
    }
57
58 View Code Duplication
    public function testORMResetIndexAddsMappings()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $client = $this->createClient(array('test_case' => 'ORM'));
61
        $resetter = $this->getResetter($client);
62
        $resetter->resetIndex('index');
63
64
        $type = $this->getType($client);
65
        $mapping = $type->getMapping();
66
67
        $this->assertNotEmpty($mapping, 'Mapping was populated');
68
    }
69
70 View Code Duplication
    public function testORMResetType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $client = $this->createClient(array('test_case' => 'ORM'));
73
        $resetter = $this->getResetter($client);
74
        $resetter->resetIndexType('index', 'type');
75
76
        $type = $this->getType($client);
77
        $mapping = $type->getMapping();
78
79
        $this->assertNotEmpty($mapping, 'Mapping was populated');
80
    }
81
82 View Code Duplication
    public function testMappingIteratorToArrayField()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        $client = $this->createClient(array('test_case' => 'ORM'));
85
        $persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
86
87
        $object = new TypeObj();
88
        $object->id = 1;
89
        $object->coll = new \ArrayIterator(array('foo', 'bar'));
90
        $persister->insertOne($object);
91
92
        $object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
93
        $object->coll->offsetUnset(1);
94
95
        $persister->replaceOne($object);
96
    }
97
98
    /**
99
     * @param Client $client
100
     *
101
     * @return \FOS\ElasticaBundle\Resetter $resetter
102
     */
103
    private function getResetter(Client $client)
104
    {
105
        return $client->getContainer()->get('fos_elastica.resetter');
106
    }
107
108
    /**
109
     * @param Client $client
110
     * @param string $type
111
     *
112
     * @return \Elastica\Type
113
     */
114
    private function getType(Client $client, $type = 'type')
115
    {
116
        return $client->getContainer()->get('fos_elastica.index.index.'.$type);
117
    }
118
119
    protected function setUp()
120
    {
121
        parent::setUp();
122
123
        $this->deleteTmpDir('Basic');
124
        $this->deleteTmpDir('ORM');
125
    }
126
127
    protected function tearDown()
128
    {
129
        parent::tearDown();
130
131
        $this->deleteTmpDir('Basic');
132
        $this->deleteTmpDir('ORM');
133
    }
134
}
135