Ignore iterator keys when converting to array
This commit is contained in:
parent
7fcbb64a15
commit
d57d430ab3
|
@ -72,6 +72,22 @@ class MappingToElasticaTest extends WebTestCase
|
||||||
$this->assertNotEmpty($mapping, 'Mapping was populated');
|
$this->assertNotEmpty($mapping, 'Mapping was populated');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMappingIteratorToArrayField()
|
||||||
|
{
|
||||||
|
$client = $this->createClient(array('test_case' => 'ORM'));
|
||||||
|
$persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
|
||||||
|
|
||||||
|
$object = new TypeObj();
|
||||||
|
$object->id = 1;
|
||||||
|
$object->coll = new \ArrayIterator(array('foo', 'bar'));
|
||||||
|
$persister->insertOne($object);
|
||||||
|
|
||||||
|
$object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
|
||||||
|
$object->coll->offsetUnset(1);
|
||||||
|
|
||||||
|
$persister->replaceOne($object);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
* @return \FOS\ElasticaBundle\Resetter $resetter
|
* @return \FOS\ElasticaBundle\Resetter $resetter
|
||||||
|
@ -95,6 +111,7 @@ class MappingToElasticaTest extends WebTestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->deleteTmpDir('Basic');
|
$this->deleteTmpDir('Basic');
|
||||||
|
$this->deleteTmpDir('ORM');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
|
@ -102,5 +119,6 @@ class MappingToElasticaTest extends WebTestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
|
||||||
$this->deleteTmpDir('Basic');
|
$this->deleteTmpDir('Basic');
|
||||||
|
$this->deleteTmpDir('ORM');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
48
Tests/Functional/SerializerTest.php
Normal file
48
Tests/Functional/SerializerTest.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the FOSElasticaBundle project.
|
||||||
|
*
|
||||||
|
* (c) Tim Nagel <tim@nagel.com.au>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FOS\ElasticaBundle\Tests\Functional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class SerializerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
public function testMappingIteratorToArrayField()
|
||||||
|
{
|
||||||
|
$client = $this->createClient(array('test_case' => 'Serializer'));
|
||||||
|
$persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
|
||||||
|
|
||||||
|
$object = new TypeObj();
|
||||||
|
$object->id = 1;
|
||||||
|
$object->coll = new \ArrayIterator(array('foo', 'bar'));
|
||||||
|
$persister->insertOne($object);
|
||||||
|
|
||||||
|
$object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
|
||||||
|
$object->coll->offsetUnset(1);
|
||||||
|
|
||||||
|
$persister->replaceOne($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->deleteTmpDir('Serializer');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
$this->deleteTmpDir('Serializer');
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,9 @@ namespace FOS\ElasticaBundle\Tests\Functional;
|
||||||
|
|
||||||
class TypeObj
|
class TypeObj
|
||||||
{
|
{
|
||||||
|
public $coll;
|
||||||
|
public $field1;
|
||||||
|
|
||||||
public function isIndexable()
|
public function isIndexable()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,4 +25,9 @@ class TypeObj
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSerializableColl()
|
||||||
|
{
|
||||||
|
return iterator_to_array($this->coll, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ fos_elastica:
|
||||||
url: http://localhost:9200
|
url: http://localhost:9200
|
||||||
indexes:
|
indexes:
|
||||||
index:
|
index:
|
||||||
index_name: foselastica_test_%kernel.environment%
|
index_name: foselastica_basic_test_%kernel.environment%
|
||||||
settings:
|
settings:
|
||||||
analysis:
|
analysis:
|
||||||
analyzer:
|
analyzer:
|
||||||
|
|
|
@ -17,27 +17,24 @@ fos_elastica:
|
||||||
clients:
|
clients:
|
||||||
default:
|
default:
|
||||||
url: http://localhost:9200
|
url: http://localhost:9200
|
||||||
serializer: ~
|
|
||||||
indexes:
|
indexes:
|
||||||
fos_elastica_test:
|
fos_elastica_orm_test:
|
||||||
types:
|
types:
|
||||||
type:
|
type:
|
||||||
properties:
|
properties:
|
||||||
field1: ~
|
field1: ~
|
||||||
index:
|
index:
|
||||||
index_name: foselastica_test_%kernel.environment%
|
index_name: foselastica_orm_test_%kernel.environment%
|
||||||
types:
|
types:
|
||||||
type:
|
type:
|
||||||
properties:
|
properties:
|
||||||
field1: ~
|
field1: ~
|
||||||
|
coll: ~
|
||||||
persistence:
|
persistence:
|
||||||
driver: orm
|
driver: orm
|
||||||
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
|
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
|
||||||
listener:
|
listener:
|
||||||
is_indexable_callback: 'object.isIndexable() && !object.isntIndexable()'
|
is_indexable_callback: 'object.isIndexable() && !object.isntIndexable()'
|
||||||
serializer:
|
|
||||||
groups: ['search']
|
|
||||||
version: 1.1
|
|
||||||
type2:
|
type2:
|
||||||
properties:
|
properties:
|
||||||
field1: ~
|
field1: ~
|
||||||
|
|
8
Tests/Functional/app/Serializer/TypeObj.yml
Normal file
8
Tests/Functional/app/Serializer/TypeObj.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
FOS\ElasticaBundle\Tests\Functional\TypeObj:
|
||||||
|
properties:
|
||||||
|
field1:
|
||||||
|
type: string
|
||||||
|
virtualProperties:
|
||||||
|
getSerializableColl:
|
||||||
|
serializedName: coll
|
||||||
|
type: array
|
13
Tests/Functional/app/Serializer/bundles.php
Normal file
13
Tests/Functional/app/Serializer/bundles.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
|
||||||
|
use FOS\ElasticaBundle\FOSElasticaBundle;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||||
|
use JMS\SerializerBundle\JMSSerializerBundle;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
new FrameworkBundle(),
|
||||||
|
new FOSElasticaBundle(),
|
||||||
|
new DoctrineBundle(),
|
||||||
|
new JMSSerializerBundle(),
|
||||||
|
);
|
42
Tests/Functional/app/Serializer/config.yml
Normal file
42
Tests/Functional/app/Serializer/config.yml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
imports:
|
||||||
|
- { resource: ./../config/config.yml }
|
||||||
|
|
||||||
|
doctrine:
|
||||||
|
dbal:
|
||||||
|
path: %kernel.cache_dir%/db.sqlite
|
||||||
|
charset: UTF8
|
||||||
|
orm:
|
||||||
|
auto_generate_proxy_classes: false
|
||||||
|
auto_mapping: false
|
||||||
|
|
||||||
|
services:
|
||||||
|
indexableService:
|
||||||
|
class: FOS\ElasticaBundle\Tests\Functional\app\ORM\IndexableService
|
||||||
|
|
||||||
|
jms_serializer:
|
||||||
|
metadata:
|
||||||
|
auto_detection: true
|
||||||
|
directories:
|
||||||
|
type_obj:
|
||||||
|
namespace_prefix: "FOS\\ElasticaBundle\\Tests\\Functional"
|
||||||
|
path: "%kernel.root_dir%/Serializer"
|
||||||
|
|
||||||
|
fos_elastica:
|
||||||
|
clients:
|
||||||
|
default:
|
||||||
|
url: http://localhost:9200
|
||||||
|
serializer: ~
|
||||||
|
indexes:
|
||||||
|
index:
|
||||||
|
index_name: foselastica_test_%kernel.environment%
|
||||||
|
types:
|
||||||
|
type:
|
||||||
|
properties:
|
||||||
|
coll: ~
|
||||||
|
field1: ~
|
||||||
|
persistence:
|
||||||
|
driver: orm
|
||||||
|
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
|
||||||
|
serializer:
|
||||||
|
groups: ['search', 'Default']
|
||||||
|
version: 1.1
|
|
@ -141,7 +141,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
||||||
};
|
};
|
||||||
|
|
||||||
if (is_array($value) || $value instanceof \Traversable || $value instanceof \ArrayAccess) {
|
if (is_array($value) || $value instanceof \Traversable || $value instanceof \ArrayAccess) {
|
||||||
$value = is_array($value) ? $value : iterator_to_array($value);
|
$value = is_array($value) ? $value : iterator_to_array($value, false);
|
||||||
array_walk_recursive($value, $normalizeValue);
|
array_walk_recursive($value, $normalizeValue);
|
||||||
} else {
|
} else {
|
||||||
$normalizeValue($value);
|
$normalizeValue($value);
|
||||||
|
|
Loading…
Reference in a new issue