public function testExtractWithPropertyNameFilterByReference() { $entity = new Asset\SimpleEntity(); $entity->setId(2); $entity->setField('foo', false); $filter = new Filter\PropertyName(array('id'), false); $this->configureObjectManagerForSimpleEntity(); $this->hydratorByReference->addFilter('propertyname', $filter); $data = $this->hydratorByReference->extract($entity); $this->assertEquals(2, $data['id']); $this->assertEquals(array('id'), array_keys($data), 'Only the "id" field should have been extracted.'); }
public function testCanLookupsForEmptyIdentifiers() { // When using hydration by reference, it won't use the public API of the entity to set values (setters) $entity = new Asset\OneToManyEntity(); $this->configureObjectManagerForOneToManyEntity(); $data = array('entities' => array('')); $entityInDatabaseWithEmptyId = new Asset\SimpleEntity(); $entityInDatabaseWithEmptyId->setId(''); $entityInDatabaseWithEmptyId->setField('baz', false); $this->objectManager->expects($this->any())->method('find')->with('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity', '')->will($this->returnValue($entityInDatabaseWithEmptyId)); $entity = $this->hydratorByValue->hydrate($data, $entity); $this->assertInstanceOf('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\OneToManyEntity', $entity); $entities = $entity->getEntities(false); $entity = $entities[0]; $this->assertEquals(1, count($entities)); $this->assertInstanceOf('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity', $entity); $this->assertSame($entityInDatabaseWithEmptyId, $entity); }