Completed
Pull Request — master (#917)
by Dmitry
08:52
created

testBuildIndexTemplateMapping()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 27
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace FOS\ElasticaBundle\Tests\Index;
4
5
use FOS\ElasticaBundle\Configuration\IndexTemplateConfig;
6
use FOS\ElasticaBundle\Configuration\TypeConfig;
7
use FOS\ElasticaBundle\Index\MappingBuilder;
8
9
class MappingBuilderTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var MappingBuilder
13
     */
14
    private $builder;
15
16
    protected function setUp()
17
    {
18
        $this->builder = new MappingBuilder();
19
    }
20
21
    public function testMappingBuilderStoreProperty()
22
    {
23
        $typeConfig = new TypeConfig('typename', array(
24
            'properties' => array(
25
                'storeless' => array(
26
                    'type' => 'string'
27
                ),
28
                'stored' => array(
29
                    'type' => 'string',
30
                    'store' => true
31
                ),
32
                'unstored' => array(
33
                    'type' => 'string',
34
                    'store' => false
35
                ),
36
            )
37
        ));
38
39
        $mapping = $this->builder->buildTypeMapping($typeConfig);
40
41
        $this->assertArrayNotHasKey('store', $mapping['properties']['storeless']);
42
        $this->assertArrayHasKey('store', $mapping['properties']['stored']);
43
        $this->assertTrue($mapping['properties']['stored']['store']);
44
        $this->assertArrayHasKey('store', $mapping['properties']['unstored']);
45
        $this->assertFalse($mapping['properties']['unstored']['store']);
46
    }
47
48
    public function testBuildIndexTemplateMapping()
49
    {
50
        /** @var \PHPUnit_Framework_MockObject_MockObject|IndexTemplateConfig $indexTemplateConfig */
51
        $indexTemplateConfig = $this->getMockBuilder('\FOS\ElasticaBundle\Configuration\IndexTemplateConfig')
52
            ->disableOriginalConstructor()
53
            ->setMethods(array('getTypes', 'getSettings', 'getTemplate'))
54
            ->getMock();
55
        $indexTemplateConfig->expects($this->once())
56
            ->method('getTypes')
57
            ->willReturn(array(new TypeConfig('type1', array('properties' => array()))));
58
        $indexTemplateConfig->expects($this->once())
59
            ->method('getSettings')
60
            ->willReturn(array('1'));
61
        $indexTemplateConfig->expects($this->once())
62
            ->method('getTemplate')
63
            ->willReturn('t*');
64
        $mappingBuilder = new MappingBuilder();
65
        $mapping = $mappingBuilder->buildIndexTemplateMapping($indexTemplateConfig);
66
        $this->assertEquals(
67
            array(
68
                'mappings' => array('type1' => new \stdClass()),
69
                'settings' => array(1),
70
                'template' => 't*',
71
            ),
72
            $mapping
73
        );
74
    }
75
76
}
77