Removed filtering of null values in transformer

This commit is contained in:
Richard Miller 2012-02-27 19:37:59 +00:00
parent 4baefe6686
commit 2e5bac1f52
2 changed files with 4 additions and 8 deletions

View file

@ -148,15 +148,13 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
);
}
public function testThatNullValuesAreFilteredOut()
public function testThatNullValuesAreNotFilteredOut()
{
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('nullValue'));
$data = $document->getData();
$this->assertInstanceOf('Elastica_Document', $document);
$this->assertEquals(123, $document->getId());
$this->assertFalse(array_key_exists('nullValue', $data));
$this->assertTrue(array_key_exists('nullValue', $data));
}
/**
@ -165,6 +163,6 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
public function testThatCannotTransformObjectWhenGetterDoesNotExists()
{
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('desc'));
$transformer->transform(new POPO(), array('desc'));
}
}

View file

@ -49,9 +49,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
if (!method_exists($class, $getter)) {
throw new RuntimeException(sprintf('The getter %s::%s does not exist', $class, $getter));
}
if (null !== $value = $this->normalizeValue($object->$getter())) {
$array[$key] = $value;
}
$array[$key] = $this->normalizeValue($object->$getter());
}
$identifierGetter = 'get'.ucfirst($this->options['identifier']);
$identifier = $object->$identifierGetter();