Completed
Push — 3.1.x ( b5e6ea...97016e )
by Karel
36:02 queued 26:01
created

MappingToElasticaTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 122
Duplicated Lines 30.33 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 5
Bugs 3 Features 2
Metric Value
wmc 9
lcom 1
cbo 6
dl 37
loc 122
rs 10
c 5
b 3
f 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getResetter() 0 4 1
A getType() 0 4 1
B testResetIndexAddsMappings() 0 24 1
A testResetType() 0 17 1
A testORMResetIndexAddsMappings() 11 11 1
A testORMResetType() 11 11 1
A testMappingIteratorToArrayField() 15 15 1
A setUp() 0 7 1
A tearDown() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
        $this->assertArrayHasKey('store', $mapping['type']['properties']['field1']);
32
        $this->assertTrue($mapping['type']['properties']['field1']['store']);
33
        $this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
34
35
        $type = $this->getType($client, 'type');
36
        $mapping = $type->getMapping();
37
        $this->assertEquals('parent', $mapping['type']['_parent']['type']);
38
39
        $parent = $this->getType($client, 'parent');
40
        $mapping = $parent->getMapping();
41
42
        $this->assertEquals('my_analyzer', $mapping['parent']['index_analyzer']);
43
        $this->assertEquals('whitespace', $mapping['parent']['search_analyzer']);
44
    }
45
46
    public function testResetType()
47
    {
48
        $client = $this->createClient(array('test_case' => 'Basic'));
49
        $resetter = $this->getResetter($client);
50
        $resetter->resetIndexType('index', 'type');
51
52
        $type = $this->getType($client);
53
        $mapping = $type->getMapping();
54
55
        $this->assertNotEmpty($mapping, 'Mapping was populated');
56
        $this->assertFalse($mapping['type']['date_detection']);
57
        $this->assertTrue($mapping['type']['numeric_detection']);
58
        $this->assertEquals(array('yyyy-MM-dd'), $mapping['type']['dynamic_date_formats']);
59
        $this->assertArrayHasKey('store', $mapping['type']['properties']['field1']);
60
        $this->assertTrue($mapping['type']['properties']['field1']['store']);
61
        $this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
62
    }
63
64 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...
65
    {
66
        $client = $this->createClient(array('test_case' => 'ORM'));
67
        $resetter = $this->getResetter($client);
68
        $resetter->resetIndex('index');
69
70
        $type = $this->getType($client);
71
        $mapping = $type->getMapping();
72
73
        $this->assertNotEmpty($mapping, 'Mapping was populated');
74
    }
75
76 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...
77
    {
78
        $client = $this->createClient(array('test_case' => 'ORM'));
79
        $resetter = $this->getResetter($client);
80
        $resetter->resetIndexType('index', 'type');
81
82
        $type = $this->getType($client);
83
        $mapping = $type->getMapping();
84
85
        $this->assertNotEmpty($mapping, 'Mapping was populated');
86
    }
87
88 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...
89
    {
90
        $client = $this->createClient(array('test_case' => 'ORM'));
91
        $persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
92
93
        $object = new TypeObj();
94
        $object->id = 1;
95
        $object->coll = new \ArrayIterator(array('foo', 'bar'));
96
        $persister->insertOne($object);
97
98
        $object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
99
        $object->coll->offsetUnset(1);
100
101
        $persister->replaceOne($object);
102
    }
103
104
    /**
105
     * @param Client $client
106
     *
107
     * @return \FOS\ElasticaBundle\Resetter $resetter
108
     */
109
    private function getResetter(Client $client)
110
    {
111
        return $client->getContainer()->get('fos_elastica.resetter');
112
    }
113
114
    /**
115
     * @param Client $client
116
     * @param string $type
117
     *
118
     * @return \Elastica\Type
119
     */
120
    private function getType(Client $client, $type = 'type')
121
    {
122
        return $client->getContainer()->get('fos_elastica.index.index.'.$type);
123
    }
124
125
    protected function setUp()
126
    {
127
        parent::setUp();
128
129
        $this->deleteTmpDir('Basic');
130
        $this->deleteTmpDir('ORM');
131
    }
132
133
    protected function tearDown()
134
    {
135
        parent::tearDown();
136
137
        $this->deleteTmpDir('Basic');
138
        $this->deleteTmpDir('ORM');
139
    }
140
}
141