forked from FriendsOfSymfony/FOSElasticaBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMappingBuilderTest.php
More file actions
98 lines (86 loc) · 3.07 KB
/
Copy pathMappingBuilderTest.php
File metadata and controls
98 lines (86 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/*
* This file is part of the FOSElasticaBundle package.
*
* (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\ElasticaBundle\Tests\Unit\Index;
use FOS\ElasticaBundle\Configuration\IndexConfig;
use FOS\ElasticaBundle\Configuration\IndexTemplateConfig;
use FOS\ElasticaBundle\Elastica\ElasticsearchVersionDetector;
use FOS\ElasticaBundle\Index\MappingBuilder;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @internal
*/
class MappingBuilderTest extends TestCase
{
private MappingBuilder $builder;
private IndexConfig $indexConfig;
protected function setUp(): void
{
$this->indexConfig = new IndexConfig(
[
'name' => 'name',
'config' => [],
'model' => null,
'mapping' => [
'properties' => [
'storeless' => [
'type' => 'text',
],
'stored' => [
'type' => 'text',
'store' => true,
],
'unstored' => [
'type' => 'text',
'store' => false,
],
],
],
]
);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->builder = new MappingBuilder($dispatcher);
}
public function testMappingBuilderStoreProperty(): void
{
$mapping = $this->builder->buildMapping(null, $this->indexConfig);
$this->assertArrayNotHasKey('store', $mapping['properties']['storeless']);
$this->assertArrayHasKey('store', $mapping['properties']['stored']);
$this->assertTrue($mapping['properties']['stored']['store']);
$this->assertArrayHasKey('store', $mapping['properties']['unstored']);
$this->assertFalse($mapping['properties']['unstored']['store']);
}
public function testBuildIndexTemplateMapping(): void
{
$config = new IndexTemplateConfig([
'index_patterns' => ['index_template_*'],
'name' => 'some_template',
'config' => [],
'mapping' => $this->indexConfig->getMapping(),
'priority' => 0,
]);
$expected = ElasticsearchVersionDetector::usesNewIndexTemplateApi()
? [
'template' => [
'mappings' => $this->indexConfig->getMapping(),
],
'index_patterns' => ['index_template_*'],
'priority' => 0,
]
: [
'index_patterns' => ['index_template_*'],
'mappings' => $this->indexConfig->getMapping(),
];
$this->assertEquals(
$expected,
$this->builder->buildIndexTemplateMapping($config)
);
}
}