diff --git a/Tests/Functional/MappingToElasticaTest.php b/Tests/Functional/MappingToElasticaTest.php index f038212..2474a1c 100644 --- a/Tests/Functional/MappingToElasticaTest.php +++ b/Tests/Functional/MappingToElasticaTest.php @@ -72,6 +72,22 @@ class MappingToElasticaTest extends WebTestCase $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 * @return \FOS\ElasticaBundle\Resetter $resetter @@ -95,6 +111,7 @@ class MappingToElasticaTest extends WebTestCase parent::setUp(); $this->deleteTmpDir('Basic'); + $this->deleteTmpDir('ORM'); } protected function tearDown() @@ -102,5 +119,6 @@ class MappingToElasticaTest extends WebTestCase parent::tearDown(); $this->deleteTmpDir('Basic'); + $this->deleteTmpDir('ORM'); } } diff --git a/Tests/Functional/SerializerTest.php b/Tests/Functional/SerializerTest.php new file mode 100644 index 0000000..3a3b8cb --- /dev/null +++ b/Tests/Functional/SerializerTest.php @@ -0,0 +1,48 @@ + + * + * 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'); + } +} diff --git a/Tests/Functional/TypeObj.php b/Tests/Functional/TypeObj.php index c264e7b..46e5968 100644 --- a/Tests/Functional/TypeObj.php +++ b/Tests/Functional/TypeObj.php @@ -13,6 +13,9 @@ namespace FOS\ElasticaBundle\Tests\Functional; class TypeObj { + public $coll; + public $field1; + public function isIndexable() { return true; @@ -22,4 +25,9 @@ class TypeObj { return false; } + + public function getSerializableColl() + { + return iterator_to_array($this->coll, false); + } } diff --git a/Tests/Functional/app/Basic/config.yml b/Tests/Functional/app/Basic/config.yml index cdc6c53..a7550b9 100644 --- a/Tests/Functional/app/Basic/config.yml +++ b/Tests/Functional/app/Basic/config.yml @@ -14,7 +14,7 @@ fos_elastica: url: http://localhost:9200 indexes: index: - index_name: foselastica_test_%kernel.environment% + index_name: foselastica_basic_test_%kernel.environment% settings: analysis: analyzer: diff --git a/Tests/Functional/app/ORM/config.yml b/Tests/Functional/app/ORM/config.yml index 9ba6830..3dc0e63 100644 --- a/Tests/Functional/app/ORM/config.yml +++ b/Tests/Functional/app/ORM/config.yml @@ -17,27 +17,24 @@ fos_elastica: clients: default: url: http://localhost:9200 - serializer: ~ indexes: - fos_elastica_test: + fos_elastica_orm_test: types: type: properties: field1: ~ index: - index_name: foselastica_test_%kernel.environment% + index_name: foselastica_orm_test_%kernel.environment% types: type: properties: field1: ~ + coll: ~ persistence: driver: orm model: FOS\ElasticaBundle\Tests\Functional\TypeObj listener: is_indexable_callback: 'object.isIndexable() && !object.isntIndexable()' - serializer: - groups: ['search'] - version: 1.1 type2: properties: field1: ~ diff --git a/Tests/Functional/app/Serializer/TypeObj.yml b/Tests/Functional/app/Serializer/TypeObj.yml new file mode 100644 index 0000000..67d6335 --- /dev/null +++ b/Tests/Functional/app/Serializer/TypeObj.yml @@ -0,0 +1,8 @@ +FOS\ElasticaBundle\Tests\Functional\TypeObj: + properties: + field1: + type: string + virtualProperties: + getSerializableColl: + serializedName: coll + type: array diff --git a/Tests/Functional/app/Serializer/bundles.php b/Tests/Functional/app/Serializer/bundles.php new file mode 100644 index 0000000..25db3fe --- /dev/null +++ b/Tests/Functional/app/Serializer/bundles.php @@ -0,0 +1,13 @@ +