Added checking the transformed values to test

This commit is contained in:
Richard Miller 2011-12-05 21:44:12 +00:00
parent a5316fe51c
commit 587d1e540e

View file

@ -4,11 +4,19 @@ namespace FOQ\ElasticaBundle\Tests\Transformer\ModelToElasticaAutoTransformer;
use FOQ\ElasticaBundle\Transformer\ModelToElasticaAutoTransformer;
class POPO
class POPO
{
public $id = 123;
public $name = 'someName';
public $desc = 'desc';
public $id = 123;
public $name = 'someName';
public $desc = 'desc';
public $float = 7.2;
public $bool = true;
public $date;
public function __construct()
{
$this->date = new \DateTime('1979-05-05');
}
public function getId()
{
@ -32,6 +40,30 @@ class POPO
{
return array('key1' => 'value1', 'key2' => 'value2');
}
public function getMultiArray()
{
return array(
'key1' => 'value1',
'key2' => array('value2', false, 123, 8.9, new \DateTime('1978-09-07')),
);
}
public function getBool()
{
return $this->bool;
}
public function getFloat()
{
return $this->float;
}
public function getDate()
{
return $this->date;
}
}
class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
@ -48,30 +80,61 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('name'));
$data = $document->getData();
$this->assertInstanceOf('Elastica_Document', $document);
$this->assertEquals(123, $document->getId());
$this->assertEquals('someName', $data['name']);
}
public function testThatCanTransformObjectWithCorrectTypes()
{
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('name', 'float', 'bool', 'date'));
$data = $document->getData();
$this->assertInstanceOf('Elastica_Document', $document);
$this->assertEquals(123, $document->getId());
$this->assertEquals('someName', $data['name']);
$this->assertEquals(7.2, $data['float']);
$this->assertEquals(true, $data['bool']);
$expectedDate = new \DateTime('1979-05-05');
$this->assertEquals($expectedDate->format('U'), $data['date']);
}
public function testThatCanTransformObjectWithIteratorValue()
{
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('iterator'));
$data = $document->getData();
$this->assertEquals(array('value1'), $data['iterator']);
}
public function testThatCanTransformObjectWithArrayValue()
{
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('array'));
$data = $document->getData();
$this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $data['array']);
}
public function testThatCanTransformObjectWithMultiDimensionalArrayValue()
{
$transformer = new ModelToElasticaAutoTransformer();
$document = $transformer->transform(new POPO(), array('multiArray'));
$data = $document->getData();
$expectedDate = new \DateTime('1978-09-07');
$this->assertEquals(
array(
'key1' => 'value1',
'key2' => array('value2', false, 123, 8.9, $expectedDate->format('U')),
), $data['multiArray']
);
}
/**
* @expectedException RuntimeException
*/