Merge branch '3.0.x'
This commit is contained in:
commit
229d4cb982
|
@ -7,6 +7,7 @@ php:
|
|||
- 5.6
|
||||
|
||||
before_script:
|
||||
- /usr/share/elasticsearch -v
|
||||
- sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/2.0.0
|
||||
- sudo service elasticsearch restart
|
||||
- echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
|
||||
|
|
|
@ -183,7 +183,7 @@ class Configuration implements ConfigurationInterface
|
|||
->treatNullLike(array())
|
||||
// BC - Renaming 'mappings' node to 'properties'
|
||||
->beforeNormalization()
|
||||
->ifTrue(function($v) { return isset($v['mappings']); })
|
||||
->ifTrue(function($v) { return array_key_exists('mappings', $v); })
|
||||
->then(function($v) {
|
||||
$v['properties'] = $v['mappings'];
|
||||
unset($v['mappings']);
|
||||
|
@ -214,7 +214,7 @@ class Configuration implements ConfigurationInterface
|
|||
foreach ($v['dynamic_templates'] as $key => $type) {
|
||||
if (is_int($key)) {
|
||||
$dt[] = $type;
|
||||
} else {
|
||||
} else {
|
||||
$dt[][$key] = $type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,11 +120,17 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
|
||||
public function hybridTransform(array $elasticaObjects)
|
||||
{
|
||||
$indexedElasticaResults = array();
|
||||
foreach ($elasticaObjects as $elasticaObject) {
|
||||
$indexedElasticaResults[$elasticaObject->getId()] = $elasticaObject;
|
||||
}
|
||||
|
||||
$objects = $this->transform($elasticaObjects);
|
||||
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($elasticaObjects); $i++) {
|
||||
$result[] = new HybridResult($elasticaObjects[$i], $objects[$i]);
|
||||
foreach ($objects as $object) {
|
||||
$id = $this->propertyAccessor->getValue($object, $this->options['identifier']);
|
||||
$result[] = new HybridResult($indexedElasticaResults[$id], $object);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
@ -7,7 +7,7 @@ A) Install FOSElasticaBundle
|
|||
FOSElasticaBundle is installed using [Composer](https://getcomposer.org).
|
||||
|
||||
```bash
|
||||
$ php composer.phar require friendsofsymfony/elastica-bundle "3.0.*@alpha"
|
||||
$ php composer.phar require friendsofsymfony/elastica-bundle "~3.0.2"
|
||||
```
|
||||
|
||||
### Elasticsearch
|
||||
|
|
66
Tests/Doctrine/AbstractElasticaToModelTransformerTest.php
Normal file
66
Tests/Doctrine/AbstractElasticaToModelTransformerTest.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace FOS\ElasticaBundle\Tests\Doctrine;
|
||||
|
||||
use Elastica\Result;
|
||||
use FOS\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
|
||||
class AbstractElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\Common\Persistence\ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $objectClass = 'stdClass';
|
||||
|
||||
/**
|
||||
* Tests if ignore_missing option is properly handled in transformHybrid() method
|
||||
*/
|
||||
public function testIgnoreMissingOptionDuringTransformHybrid()
|
||||
{
|
||||
$transformer = $this->getMock(
|
||||
'FOS\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer',
|
||||
array('findByIdentifiers'),
|
||||
array($this->registry, $this->objectClass, array('ignore_missing' => true))
|
||||
);
|
||||
|
||||
$transformer->setPropertyAccessor(PropertyAccess::createPropertyAccessor());
|
||||
|
||||
$firstOrmResult = new \stdClass();
|
||||
$firstOrmResult->id = 1;
|
||||
$secondOrmResult = new \stdClass();
|
||||
$secondOrmResult->id = 3;
|
||||
$transformer->expects($this->once())
|
||||
->method('findByIdentifiers')
|
||||
->with(array(1, 2, 3))
|
||||
->willReturn(array($firstOrmResult, $secondOrmResult));
|
||||
|
||||
$firstElasticaResult = new Result(array('_id' => 1));
|
||||
$secondElasticaResult = new Result(array('_id' => 2));
|
||||
$thirdElasticaResult = new Result(array('_id' => 3));
|
||||
|
||||
$hybridResults = $transformer->hybridTransform(array($firstElasticaResult, $secondElasticaResult, $thirdElasticaResult));
|
||||
|
||||
$this->assertCount(2, $hybridResults);
|
||||
$this->assertEquals($firstOrmResult, $hybridResults[0]->getTransformed());
|
||||
$this->assertEquals($firstElasticaResult, $hybridResults[0]->getResult());
|
||||
$this->assertEquals($secondOrmResult, $hybridResults[1]->getTransformed());
|
||||
$this->assertEquals($thirdElasticaResult, $hybridResults[1]->getResult());
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!interface_exists('Doctrine\Common\Persistence\ManagerRegistry')) {
|
||||
$this->markTestSkipped('Doctrine Common is not present');
|
||||
}
|
||||
|
||||
$this->registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ class ConfigurationManagerTest extends WebTestCase
|
|||
$index = $manager->getIndexConfiguration('index');
|
||||
|
||||
$this->assertEquals('index', $index->getName());
|
||||
$this->assertCount(2, $index->getTypes());
|
||||
$this->assertGreaterThanOrEqual(2, count($index->getTypes()));
|
||||
$this->assertInstanceOf('FOS\\ElasticaBundle\\Configuration\\TypeConfig', $index->getType('type'));
|
||||
$this->assertInstanceOf('FOS\\ElasticaBundle\\Configuration\\TypeConfig', $index->getType('parent'));
|
||||
}
|
||||
|
|
|
@ -32,6 +32,13 @@ class SerializerTest extends WebTestCase
|
|||
$persister->replaceOne($object);
|
||||
}
|
||||
|
||||
public function testUnmappedType()
|
||||
{
|
||||
$client = $this->createClient(array('test_case' => 'Serializer'));
|
||||
$resetter = $client->getContainer()->get('fos_elastica.resetter');
|
||||
$resetter->resetIndex('index');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
|
|
@ -83,3 +83,5 @@ fos_elastica:
|
|||
type: "parent"
|
||||
property: "parent"
|
||||
identifier: "id"
|
||||
null_mappings:
|
||||
mappings: ~
|
||||
|
|
|
@ -40,3 +40,11 @@ fos_elastica:
|
|||
serializer:
|
||||
groups: ['search', 'Default']
|
||||
version: 1.1
|
||||
unmapped:
|
||||
persistence:
|
||||
driver: orm
|
||||
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
|
||||
serializer:
|
||||
groups: ['search', 'Default']
|
||||
version: 1.1
|
||||
|
||||
|
|
Loading…
Reference in a new issue