From a879d3c1c98b4e706148928355d2a114720783ab Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Thu, 26 Jun 2014 17:29:16 +1000 Subject: [PATCH] Fix ClassCastException when no settings are present --- Index/MappingBuilder.php | 6 +++++- Tests/Functional/MappingToElasticaTest.php | 24 ++++++++++++++++++++++ Tests/Functional/app/ORM/config.yml | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Index/MappingBuilder.php b/Index/MappingBuilder.php index 53524ac..0751ce7 100644 --- a/Index/MappingBuilder.php +++ b/Index/MappingBuilder.php @@ -31,10 +31,14 @@ class MappingBuilder $mapping = array( 'mappings' => $typeMappings, - 'settings' => $indexConfig->getSettings(), // 'warmers' => $indexConfig->getWarmers(), ); + $settings = $indexConfig->getSettings(); + if ($settings) { + $mapping['settings'] = $settings; + } + return $mapping; } diff --git a/Tests/Functional/MappingToElasticaTest.php b/Tests/Functional/MappingToElasticaTest.php index bffcf76..390f854 100644 --- a/Tests/Functional/MappingToElasticaTest.php +++ b/Tests/Functional/MappingToElasticaTest.php @@ -42,6 +42,30 @@ class MappingToElasticaTest extends WebTestCase $this->assertNotEmpty($mapping, 'Mapping was populated'); } + public function testORMResetIndexAddsMappings() + { + $client = $this->createClient(array('test_case' => 'ORM')); + $resetter = $this->getResetter($client); + $resetter->resetIndex('index'); + + $type = $this->getType($client); + $mapping = $type->getMapping(); + + $this->assertNotEmpty($mapping, 'Mapping was populated'); + } + + public function testORMResetType() + { + $client = $this->createClient(array('test_case' => 'ORM')); + $resetter = $this->getResetter($client); + $resetter->resetIndexType('index', 'type'); + + $type = $this->getType($client); + $mapping = $type->getMapping(); + + $this->assertNotEmpty($mapping, 'Mapping was populated'); + } + /** * @param Client $client * @return \FOS\ElasticaBundle\Resetter $resetter diff --git a/Tests/Functional/app/ORM/config.yml b/Tests/Functional/app/ORM/config.yml index 2c7c692..448d62b 100644 --- a/Tests/Functional/app/ORM/config.yml +++ b/Tests/Functional/app/ORM/config.yml @@ -43,11 +43,12 @@ fos_elastica: listener: is_indexable_callback: 'object.isntIndexable()' type3: - properties: + mappings: field1: ~ persistence: driver: orm model: FOS\ElasticaBundle\Tests\Functional\TypeObj + finder: ~ + provider: ~ listener: is_indexable_callback: 'isntIndexable' -