1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This file is part of the FOSElasticaBundle project. |
14
|
|
|
* |
15
|
|
|
* (c) Tim Nagel <[email protected]> |
16
|
|
|
* |
17
|
|
|
* This source file is subject to the MIT license that is bundled |
18
|
|
|
* with this source code in the file LICENSE. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace FOS\ElasticaBundle\Tests\Functional; |
22
|
|
|
|
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Client; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @group functional |
27
|
|
|
*/ |
28
|
|
|
class MappingToElasticaTest extends WebTestCase |
29
|
|
|
{ |
30
|
|
|
public function testResetIndexAddsMappings() |
31
|
|
|
{ |
32
|
|
|
static::bootKernel(['test_case' => 'Basic']); |
33
|
|
|
$resetter = $this->getResetter(); |
34
|
|
|
$resetter->resetIndex('index'); |
35
|
|
|
|
36
|
|
|
$type = $this->getType(); |
37
|
|
|
$mapping = $type->getMapping(); |
38
|
|
|
|
39
|
|
|
$this->assertNotEmpty($mapping, 'Mapping was populated'); |
40
|
|
|
|
41
|
|
|
$type = $this->getType(); |
42
|
|
|
$mapping = $type->getMapping(); |
43
|
|
|
$this->assertSame('parent', $mapping['type']['_parent']['type']); |
44
|
|
|
|
45
|
|
|
$this->assertSame('strict', $mapping['type']['dynamic']); |
46
|
|
|
$this->assertArrayHasKey('dynamic', $mapping['type']['properties']['dynamic_allowed']); |
47
|
|
|
$this->assertSame('true', $mapping['type']['properties']['dynamic_allowed']['dynamic']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testResetType() |
51
|
|
|
{ |
52
|
|
|
static::bootKernel(['test_case' => 'Basic']); |
53
|
|
|
$resetter = $this->getResetter(); |
54
|
|
|
$resetter->resetIndexType('index', 'type'); |
55
|
|
|
|
56
|
|
|
$type = $this->getType(); |
57
|
|
|
$mapping = $type->getMapping(); |
58
|
|
|
|
59
|
|
|
$this->assertNotEmpty($mapping, 'Mapping was populated'); |
60
|
|
|
$this->assertFalse($mapping['type']['date_detection']); |
61
|
|
|
$this->assertTrue($mapping['type']['numeric_detection']); |
62
|
|
|
$this->assertSame(['yyyy-MM-dd'], $mapping['type']['dynamic_date_formats']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testORMResetIndexAddsMappings() |
66
|
|
|
{ |
67
|
|
|
static::bootKernel(['test_case' => 'ORM']); |
68
|
|
|
$resetter = $this->getResetter(); |
69
|
|
|
$resetter->resetIndex('index'); |
70
|
|
|
|
71
|
|
|
$type = $this->getType(); |
72
|
|
|
$mapping = $type->getMapping(); |
73
|
|
|
|
74
|
|
|
$this->assertNotEmpty($mapping, 'Mapping was populated'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
public function testORMResetType() |
78
|
|
|
{ |
79
|
|
|
static::bootKernel(['test_case' => 'ORM']); |
80
|
|
|
$resetter = $this->getResetter(); |
81
|
|
|
$resetter->resetIndexType('index', 'type'); |
82
|
|
|
|
83
|
|
|
$type = $this->getType(); |
84
|
|
|
$mapping = $type->getMapping(); |
85
|
|
|
|
86
|
|
|
$this->assertNotEmpty($mapping, 'Mapping was populated'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
View Code Duplication |
public function testMappingIteratorToArrayField() |
90
|
|
|
{ |
91
|
|
|
static::bootKernel(['test_case' => 'ORM']); |
92
|
|
|
$persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.index.type'); |
93
|
|
|
|
94
|
|
|
$object = new TypeObj(); |
95
|
|
|
$object->id = 1; |
96
|
|
|
$object->coll = new \ArrayIterator(['foo', 'bar']); |
97
|
|
|
$persister->insertOne($object); |
98
|
|
|
|
99
|
|
|
$object->coll = new \ArrayIterator(['foo', 'bar', 'bazz']); |
100
|
|
|
$object->coll->offsetUnset(1); |
101
|
|
|
|
102
|
|
|
$persister->replaceOne($object); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return \FOS\ElasticaBundle\Index\Resetter $resetter |
107
|
|
|
*/ |
108
|
|
|
private function getResetter() |
109
|
|
|
{ |
110
|
|
|
return static::$kernel->getContainer()->get('fos_elastica.resetter'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $type |
115
|
|
|
* |
116
|
|
|
* @return \Elastica\Type |
117
|
|
|
*/ |
118
|
|
|
private function getType($type = 'type') |
119
|
|
|
{ |
120
|
|
|
return static::$kernel->getContainer()->get('fos_elastica.index.index.'.$type); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|