Skip to content

Commit 90a554f

Browse files
committed
Merge branch 'pr/622'
2 parents be4af0d + d57d430 commit 90a554f

File tree

9 files changed

+142
-8
lines changed

9 files changed

+142
-8
lines changed

Tests/Functional/MappingToElasticaTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ public function testORMResetType()
7272
$this->assertNotEmpty($mapping, 'Mapping was populated');
7373
}
7474

75+
public function testMappingIteratorToArrayField()
76+
{
77+
$client = $this->createClient(array('test_case' => 'ORM'));
78+
$persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
79+
80+
$object = new TypeObj();
81+
$object->id = 1;
82+
$object->coll = new \ArrayIterator(array('foo', 'bar'));
83+
$persister->insertOne($object);
84+
85+
$object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
86+
$object->coll->offsetUnset(1);
87+
88+
$persister->replaceOne($object);
89+
}
90+
7591
/**
7692
* @param Client $client
7793
* @return \FOS\ElasticaBundle\Resetter $resetter
@@ -95,12 +111,14 @@ protected function setUp()
95111
parent::setUp();
96112

97113
$this->deleteTmpDir('Basic');
114+
$this->deleteTmpDir('ORM');
98115
}
99116

100117
protected function tearDown()
101118
{
102119
parent::tearDown();
103120

104121
$this->deleteTmpDir('Basic');
122+
$this->deleteTmpDir('ORM');
105123
}
106124
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
/**
15+
* @group functional
16+
*/
17+
class SerializerTest extends WebTestCase
18+
{
19+
public function testMappingIteratorToArrayField()
20+
{
21+
$client = $this->createClient(array('test_case' => 'Serializer'));
22+
$persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
23+
24+
$object = new TypeObj();
25+
$object->id = 1;
26+
$object->coll = new \ArrayIterator(array('foo', 'bar'));
27+
$persister->insertOne($object);
28+
29+
$object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
30+
$object->coll->offsetUnset(1);
31+
32+
$persister->replaceOne($object);
33+
}
34+
35+
protected function setUp()
36+
{
37+
parent::setUp();
38+
39+
$this->deleteTmpDir('Serializer');
40+
}
41+
42+
protected function tearDown()
43+
{
44+
parent::tearDown();
45+
46+
$this->deleteTmpDir('Serializer');
47+
}
48+
}

Tests/Functional/TypeObj.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class TypeObj
1515
{
16+
public $coll;
17+
public $field1;
18+
1619
public function isIndexable()
1720
{
1821
return true;
@@ -22,4 +25,9 @@ public function isntIndexable()
2225
{
2326
return false;
2427
}
28+
29+
public function getSerializableColl()
30+
{
31+
return iterator_to_array($this->coll, false);
32+
}
2533
}

Tests/Functional/app/Basic/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fos_elastica:
1919
url: http://localhost:9200
2020
indexes:
2121
index:
22-
index_name: foselastica_test_%kernel.environment%
22+
index_name: foselastica_basic_test_%kernel.environment%
2323
settings:
2424
analysis:
2525
analyzer:

Tests/Functional/app/ORM/config.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,24 @@ fos_elastica:
1717
clients:
1818
default:
1919
url: http://localhost:9200
20-
serializer: ~
2120
indexes:
22-
fos_elastica_test:
21+
fos_elastica_orm_test:
2322
types:
2423
type:
2524
properties:
2625
field1: ~
2726
index:
28-
index_name: foselastica_test_%kernel.environment%
27+
index_name: foselastica_orm_test_%kernel.environment%
2928
types:
3029
type:
3130
properties:
3231
field1: ~
32+
coll: ~
3333
persistence:
3434
driver: orm
3535
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
3636
listener:
3737
is_indexable_callback: 'object.isIndexable() && !object.isntIndexable()'
38-
serializer:
39-
groups: ['search']
40-
version: 1.1
4138
type2:
4239
properties:
4340
field1: ~
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FOS\ElasticaBundle\Tests\Functional\TypeObj:
2+
properties:
3+
field1:
4+
type: string
5+
virtualProperties:
6+
getSerializableColl:
7+
serializedName: coll
8+
type: array
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
4+
use FOS\ElasticaBundle\FOSElasticaBundle;
5+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
6+
use JMS\SerializerBundle\JMSSerializerBundle;
7+
8+
return array(
9+
new FrameworkBundle(),
10+
new FOSElasticaBundle(),
11+
new DoctrineBundle(),
12+
new JMSSerializerBundle(),
13+
);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
imports:
2+
- { resource: ./../config/config.yml }
3+
4+
doctrine:
5+
dbal:
6+
path: %kernel.cache_dir%/db.sqlite
7+
charset: UTF8
8+
orm:
9+
auto_generate_proxy_classes: false
10+
auto_mapping: false
11+
12+
services:
13+
indexableService:
14+
class: FOS\ElasticaBundle\Tests\Functional\app\ORM\IndexableService
15+
16+
jms_serializer:
17+
metadata:
18+
auto_detection: true
19+
directories:
20+
type_obj:
21+
namespace_prefix: "FOS\\ElasticaBundle\\Tests\\Functional"
22+
path: "%kernel.root_dir%/Serializer"
23+
24+
fos_elastica:
25+
clients:
26+
default:
27+
url: http://localhost:9200
28+
serializer: ~
29+
indexes:
30+
index:
31+
index_name: foselastica_test_%kernel.environment%
32+
types:
33+
type:
34+
properties:
35+
coll: ~
36+
field1: ~
37+
persistence:
38+
driver: orm
39+
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
40+
serializer:
41+
groups: ['search', 'Default']
42+
version: 1.1

Transformer/ModelToElasticaAutoTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function normalizeValue($value)
141141
};
142142

143143
if (is_array($value) || $value instanceof \Traversable || $value instanceof \ArrayAccess) {
144-
$value = is_array($value) ? $value : iterator_to_array($value);
144+
$value = is_array($value) ? $value : iterator_to_array($value, false);
145145
array_walk_recursive($value, $normalizeValue);
146146
} else {
147147
$normalizeValue($value);

0 commit comments

Comments
 (0)