Esempio n. 1
0
 /**
  * @dataProvider valueDataProvider
  * @param mixed $fieldValue
  */
 public function testFixEntityAssociationFieldsEntity($fieldValue)
 {
     $entity = new \stdClass();
     $entity->field = $fieldValue;
     if ($fieldValue instanceof ArrayCollection) {
         $linkedEntity = $fieldValue->getIterator()->offsetGet(0);
     } else {
         $linkedEntity = $fieldValue;
     }
     $this->fieldHelper->expects($this->once())->method('getRelations')->with(get_class($entity))->will($this->returnValue([['name' => 'field']]));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $metadata->expects($this->once())->method('getIdentifierValues')->with($linkedEntity)->will($this->returnValue('id'));
     $this->entityManager->expects($this->once())->method('getClassMetadata')->with(get_class($entity))->will($this->returnValue($metadata));
     $uow = $this->getMockBuilder('\\Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
     $uow->expects($this->once())->method('getEntityState')->with($linkedEntity)->will($this->returnValue(UnitOfWork::STATE_DETACHED));
     $this->entityManager->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uow));
     $this->entityManager->expects($this->once())->method('getReference')->with(get_class($entity), 'id')->will($this->returnCallback(function () use($entity) {
         $entity->reloaded = true;
         return $entity;
     }));
     $this->fixer->fixEntityAssociationFields($entity, 0);
     if ($fieldValue instanceof ArrayCollection) {
         $this->assertTrue($entity->field->getIterator()->offsetGet(0)->reloaded);
     } else {
         $this->assertTrue($entity->field->reloaded);
     }
 }
 /**
  * @param mixed $expected
  * @param array $data
  *
  * @dataProvider denormalizeDataProvider
  */
 public function testDenormalize($expected, array $data)
 {
     $this->fieldHelper->expects($this->once())->method('getFields')->willReturn([['name' => 'incrementId'], ['name' => 'paymentDetails']]);
     $this->fieldHelper->expects($this->once())->method('setObjectValue')->will($this->returnCallback(function ($result, $fieldName, $value) {
         $propertyAccessor = PropertyAccess::createPropertyAccessor();
         $propertyAccessor->setValue($result, $fieldName, $value);
     }));
     /** @var Order $order */
     $order = $this->normalizer->denormalize($data, 'OroCRM\\Bundle\\MagentoBundle\\Entity\\Order');
     $this->assertEquals($expected, $order->getPaymentDetails());
 }
Esempio n. 3
0
 protected function setUp()
 {
     $this->eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->fieldHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Field\\FieldHelper')->disableOriginalConstructor()->getMock();
     $this->fieldHelper->expects($this->any())->method('getIdentityValues')->willReturn([]);
     $this->fieldHelper->expects($this->any())->method('getFields')->willReturn([]);
     $this->databaseHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Field\\DatabaseHelper')->disableOriginalConstructor()->getMock();
     $this->strategyHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Strategy\\Import\\ImportStrategyHelper')->disableOriginalConstructor()->getMock();
     $this->defaultOwnerHelper = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\ImportExport\\Helper\\DefaultOwnerHelper')->disableOriginalConstructor()->getMock();
     $this->channelHelper = $this->getMockBuilder('OroCRM\\Bundle\\ChannelBundle\\ImportExport\\Helper\\ChannelHelper')->disableOriginalConstructor()->getMock();
     $this->addressHelper = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\ImportExport\\Strategy\\StrategyHelper\\AddressImportHelper')->disableOriginalConstructor()->getMock();
     $this->stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock();
     $this->jobExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution')->disableOriginalConstructor()->getMock();
     $this->stepExecution->expects($this->any())->method('getJobExecution')->will($this->returnValue($this->jobExecution));
     $this->logger = new NullLogger();
 }