public function testMapDataToFormsIgnoresEmptyData() { $propertyPath = $this->getPropertyPath('engine'); $this->propertyAccessor->expects($this->never())->method('getValue'); $config = new FormConfigBuilder('name', '\\stdClass', $this->dispatcher); $config->setByReference(true); $config->setPropertyPath($propertyPath); $form = $this->getForm($config); $this->mapper->mapDataToForms(null, array($form)); $this->assertNull($form->getData()); }
public function testMapDataToFormsSetsDefaultDataIfPassedDataIsEmptyArray() { $default = new \stdClass(); $propertyPath = $this->getPropertyPath('engine'); $this->propertyAccessor->expects($this->never())->method('getValue'); $config = new FormConfigBuilder('name', '\\stdClass', $this->dispatcher); $config->setByReference(true); $config->setPropertyPath($propertyPath); $config->setData($default); $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->setConstructorArgs(array($config))->setMethods(array('setData'))->getMock(); $form->expects($this->once())->method('setData')->with($default); $this->mapper->mapDataToForms(array(), array($form)); }
public function testMapDataToFormsSkipsVirtualForms() { $car = new \stdClass(); $engine = new \stdClass(); $propertyPath = $this->getPropertyPath('engine'); $propertyPath->expects($this->once())->method('getValue')->with($car)->will($this->returnValue($engine)); $config = new FormConfig('name', '\\stdClass', $this->dispatcher); $config->setByReference(true); $config->setVirtual(true); $form = $this->getForm($config); $config = new FormConfig('engine', '\\stdClass', $this->dispatcher); $config->setByReference(true); $config->setPropertyPath($propertyPath); $child = $this->getForm($config); $form->add($child); $this->mapper->mapDataToForms($car, array($form)); $this->assertNull($form->getData()); $this->assertSame($engine, $child->getData()); }