Add date format field

This commit is contained in:
Karel Souffriau 2013-10-28 17:07:49 +01:00
parent 4a889406e9
commit 9d1201099d
3 changed files with 54 additions and 1 deletions

View file

@ -325,7 +325,8 @@ class Configuration implements ConfigurationInterface
->scalarNode('type')->end()
->scalarNode('identifier')->defaultValue('id')->end()
->end()
->end();
->end()
->scalarNode('format')->end();
if (isset($nestings['fields'])) {
$this->addNestedFieldConfig($node, $nestings, 'fields');

View file

@ -666,3 +666,21 @@ fos_elastica:
provider:
finder:
```
#### Date format example
If you want to specify a [date format](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html):
```yaml
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
site:
types:
user:
mappings:
username: { type: string }
lastlogin: { type: date, format: basic_date_time }
birthday: { type: date, format: "yyyy-MM-dd" }
```

View file

@ -0,0 +1,34 @@
<?php
namespace FOS\ElasticaBundle\Tests\Resetter\DependencyInjection;
use FOS\ElasticaBundle\DependencyInjection\Configuration;
/**
* ConfigurationTest
*/
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Configuration
*/
private $configuration;
public function setUp()
{
$this->configuration = new Configuration(array());
}
public function testEmptyConfigContainsFormatMappingOptionNode()
{
$tree = $this->configuration->getConfigTree();
$children = $tree->getChildren();
$children = $children['indexes']->getPrototype()->getChildren();
$typeNodes = $children['types']->getPrototype()->getChildren();
$mappings = $typeNodes['mappings']->getPrototype()->getChildren();
$this->assertArrayHasKey('format', $mappings);
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $mappings['format']);
$this->assertNull($mappings['format']->getDefaultValue());
}
}