function it_normalizes_a_step_execution(StepExecution $stepExecution, BatchStatus $status, \DateTime $startTime, $translator) { $stepExecution->getStepName()->willReturn('export'); $translator->trans('export')->willReturn('Export step'); $stepExecution->getSummary()->willReturn(['read' => 12, 'write' => 50]); $translator->trans('job_execution.summary.read')->willReturn('Read'); $translator->trans('job_execution.summary.write')->willReturn('Write'); $stepExecution->getStatus()->willReturn($status); $status->getValue()->willReturn(9); $translator->trans('pim_import_export.batch_status.9')->willReturn('PENDING'); $stepExecution->getStartTime()->willReturn($startTime); $stepExecution->getEndTime()->willReturn(null); $startTime->getTimestamp()->willReturn(1411400461); $utcStartTime = new \DateTime(); $utcStartTime->setTimestamp(1411400461); $finalDate = $utcStartTime->format('Y-m-d g:i:s A'); $stepExecution->getWarnings()->willReturn(new ArrayCollection([new Warning($stepExecution->getWrappedObject(), 'a_warning', 'warning_reason', ['foo' => 'bar'], ['a' => 'A', 'b' => 'B', 'c' => 'C'])])); $translator->trans('a_warning')->willReturn('Reader'); $translator->trans(12)->willReturn(12); $translator->trans(50)->willReturn(50); $translator->trans('warning_reason', ['foo' => 'bar'])->willReturn('WARNING!'); $stepExecution->getFailureExceptions()->willReturn([['message' => 'a_failure', 'messageParameters' => ['foo' => 'bar']]]); $translator->trans('a_failure', ['foo' => 'bar'])->willReturn('FAIL!'); $this->normalize($stepExecution, 'any')->shouldReturn(['label' => 'Export step', 'status' => 'PENDING', 'summary' => ['Read' => 12, 'Write' => 50], 'startedAt' => $finalDate, 'endedAt' => null, 'warnings' => [['label' => 'Reader', 'reason' => 'WARNING!', 'item' => ['a' => 'A', 'b' => 'B', 'c' => 'C']]], 'failures' => ['FAIL!']]); }
function it_throws_an_exception_if_no_job_configuration_is_found($jobConfigurationRepo, StepExecution $stepExecution, JobExecution $jobExecution) { $stepExecution->getJobExecution()->willReturn($jobExecution); $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn(null); $this->setStepExecution($stepExecution); $this->shouldThrow('Doctrine\\ORM\\EntityNotFoundException')->during('read'); }
/** * @return ExecutionContext */ protected function getJobContext() { if (!$this->stepExecution) { throw new \InvalidArgumentException('Missing StepExecution'); } return $this->stepExecution->getJobExecution()->getExecutionContext(); }
public function process($item) { $sku = (string) $item['sku']; $attribute = $this->productManager->getIdentifierAttribute(); $product = $this->productManager->findByIdentifier($sku); // if (!$product) { // $product = $this->productManager->createProduct(); // $value = $this->productManager->createProductValue(); // $value->setAttribute($attribute); // $value->setData($sku); // $product->addValue($value); // $this->stepExecution->incrementSummaryInfo('create'); // return $product; // } else { if (!$product) { $data = current((array) $item); $this->stepExecution->incrementSummaryInfo('skip'); throw new InvalidItemException(sprintf('Skip the existing %s product', $sku), $data); } else { $product_tab = array(); $product_tab[] = $product; $this->productUpdater->setValue($product_tab, 'price', [['data' => (string) $item['price'], 'currency' => (string) $item['currency']]]); return $product; } // } }
public function write(array $items) { foreach ($items as $product) { $this->productManager->save($product); $this->stepExecution->incrementSummaryInfo('save'); } }
/** * @param object $item */ protected function incrementCount($item) { if ($item->getId()) { $this->stepExecution->incrementSummaryInfo('update'); } else { $this->stepExecution->incrementSummaryInfo('create'); } }
/** * {@inheritdoc} */ public function updateStepExecution(StepExecution $stepExecution) { $jobExecution = $stepExecution->getJobExecution(); if ($jobExecution) { $this->updateJobExecution($jobExecution); } parent::updateStepExecution($stepExecution); }
function it_reads_several_entities_from_a_yml_file_incrementing_summary_info(StepExecution $stepExecution) { $this->beConstructedWith(true, false); $stepExecution->incrementSummaryInfo('read_lines')->shouldBeCalled(); $this->setFilePath(realpath(__DIR__ . '/../../../../../../features/Context/fixtures/fake_products_with_code.yml')); $this->setStepExecution($stepExecution); $this->read()->shouldReturn(['mug_akeneo' => ['sku' => 'mug_akeneo'], 't_shirt_akeneo_purple' => ['sku' => 't_shirt_akeneo_purple', 'color' => 'purple'], 'mouse_akeneo' => ['sku' => 'mouse_akeneo']]); }
function it_increments_summary_info(StepExecution $stepExecution, ProductInterface $product1, ProductInterface $product2) { $product1->getId()->willReturn('45'); $product2->getId()->willReturn(null); $stepExecution->incrementSummaryInfo('update')->shouldBeCalled(); $stepExecution->incrementSummaryInfo('create')->shouldBeCalled(); $this->setStepExecution($stepExecution); $this->write([$product1, $product2]); }
public function write(array $items) { if (null === $this->file) { $this->file = new \SplFileObject($this->filePath, "w"); } foreach ($items as $product) { $this->file->fputcsv($product); $this->stepExecution->incrementSummaryInfo('write'); } }
/** * @param array $objects */ protected function incrementCount(array $objects) { foreach ($objects as $object) { if ($object->getId()) { $this->stepExecution->incrementSummaryInfo('process'); } else { $this->stepExecution->incrementSummaryInfo('create'); } } }
/** * {@inheritdoc} */ public function read() { if (!$this->cursor) { $this->cursor = $this->getQuery()->iterate(); } if ($data = $this->cursor->next()) { $this->stepExecution->incrementSummaryInfo('read'); return $data; } }
/** * Returns the messages for a step execution * * @param StepExecution $stepExecution * * @return string */ protected function getStepExecutionMessages(StepExecution $stepExecution) { $message = ''; foreach ($stepExecution->getFailureExceptions() as $exception) { $message .= $this->getFailureExceptionMessage(sprintf('STEP %s', $stepExecution->getStepName()), $exception); } foreach ($stepExecution->getWarnings() as $warning) { $message .= $this->getWarningMessage($warning); } return $message; }
/** * {@inheritdoc} */ public function read() { if (null === $this->results) { $items = $this->readItems(); $this->results = new \ArrayIterator($items); } if (null !== ($result = $this->results->current())) { $this->results->next(); $this->stepExecution->incrementSummaryInfo('read'); } return $result; }
/** * {@inheritdoc} */ public function read() { if (!$this->isExecuted) { $this->isExecuted = true; $this->results = $this->getResults(); } if (null !== ($result = $this->results->current())) { $this->results->next(); $this->stepExecution->incrementSummaryInfo('read'); } return $result; }
function it_throws_an_exception_if_an_error_occurs_during_processing($transformer, $validator, $managerRegistry, ProductInterface $product, ColumnInfo $columnInfo, ObjectManager $objectManager, StepExecution $stepExecution) { $item = ['sku' => 'AKNTS', 'family' => 'tshirts', 'groups' => 'akeneo_tshirt', 'categories' => 'tshirts,goodies', 'SUBSTITUTION-groups' => '', 'SUBSTITUTION-products' => 'AKNTS_WPS,AKNTS_PBS,AKNTS_PWS', 'description-en_US-mobile' => '<p>Akeneo T-Shirt</p>', 'not_empty_attribute' => '']; $transformer->transform('Pim\\Component\\Catalog\\Model\\Product', $item, ['enabled' => true])->willReturn($product); $transformer->getErrors('Pim\\Component\\Catalog\\Model\\Product')->willReturn([]); $transformer->getTransformedColumnsInfo('Pim\\Component\\Catalog\\Model\\Product')->willReturn([$columnInfo]); $validator->validate($product, [$columnInfo], $item, [])->willReturn(['AKNTS' => [["The value \"\" for not empty attribute \"not_empty_attribute\" is empty"]]]); $managerRegistry->getManagerForClass(Argument::type('string'))->willReturn($objectManager); $stepExecution->incrementSummaryInfo('skip')->shouldBeCalled(); $this->setStepExecution($stepExecution); $this->shouldThrow(new InvalidItemException('AKNTS: ', $item))->duringProcess($item); }
public function testProcessWithoutCustomer() { /** @var NewsletterSubscriber $newsletterSubscriber */ $newsletterSubscriber = $this->getReference('newsletter_subscriber2'); $newsletterSubscriber->setCustomer(null); $em = $this->getContainer()->get('doctrine')->getManager(); $em->persist($newsletterSubscriber); $em->flush($newsletterSubscriber); $this->strategy->setEntityName(get_class($newsletterSubscriber)); $this->assertEquals($newsletterSubscriber, $this->strategy->process($newsletterSubscriber)); $this->assertEmpty($this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessSubscribers')); $this->assertEmpty($this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessCustomerIds')); }
function let(NotificationManager $manager, JobExecutionEvent $event, JobExecution $jobExecution, StepExecution $stepExecution, ArrayCollection $warnings, JobInstance $jobInstance, UserInterface $user, BatchStatus $status) { $this->beConstructedWith($manager); $jobExecution->getUser()->willReturn($user); $jobExecution->getStepExecutions()->willReturn([$stepExecution]); $jobExecution->getStatus()->willReturn($status); $jobExecution->getJobInstance()->willReturn($jobInstance); $stepExecution->getWarnings()->willReturn($warnings); $jobExecution->getId()->willReturn(5); $jobInstance->getType()->willReturn('export'); $jobInstance->getLabel()->willReturn('Foo export'); $event->getJobExecution()->willReturn($jobExecution); }
function it_adds_invalid_values_to_product($propertyAdder, $validator, ProductInterface $product, StepExecution $stepExecution, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration) { $violation = new ConstraintViolation('error2', 'spec', [], '', '', $product); $violations = new ConstraintViolationList([$violation, $violation]); $validator->validate($product)->willReturn($violations); $stepExecution->getJobExecution()->willReturn($jobExecution); $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration); $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => [['field' => 'categories', 'value' => ['office', 'bedroom']]]])); $propertyAdder->addData($product, 'categories', ['office', 'bedroom'])->shouldBeCalled(); $stepExecution->addWarning(Argument::cetera())->shouldBeCalled(); $stepExecution->incrementSummaryInfo('skipped_products')->shouldBeCalled(); $this->setStepExecution($stepExecution); $this->process($product); }
public function read() { if (!isset($this->iterator)) { $this->initializeIterator(); } if (!$this->iterator->valid()) { return null; } $current = $this->iterator->current(); if ($this->stepExecution) { $this->stepExecution->incrementSummaryInfo('read'); } $this->iterator->next(); return $current; }
public function read() { if (!isset($this->iterator)) { $this->initializeIterator(); } if (!$this->iterator->valid()) { return null; } $current = $this->iterator->current(); if ($this->stepExecution) { $this->stepExecution->incrementSummaryInfo('read'); } $this->iterator->next(); return $this->convertNumericIdentifierToString($current); }
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(); }
/** * @return ExecutionContext */ protected function getExecutionContext() { if (!$this->stepExecution) { throw new \InvalidArgumentException('Execution context is not configured'); } return $this->stepExecution->getJobExecution()->getExecutionContext(); }
/** * @param int $nbSkippedProducts * @param array $skippedMessages */ protected function incrementSkippedProductsCount($nbSkippedProducts, $skippedMessages) { $this->stepExecution->incrementSummaryInfo('skip_products', $nbSkippedProducts); foreach ($skippedMessages as $productIdentifier => $messages) { $this->stepExecution->addWarning($this->getName(), sprintf('Copy of values to product "%s" skipped.', $productIdentifier), [], $messages); } }
function it_reads_products($entityManager, $jobRepository, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobInstance $jobInstance, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration, ProductQueryBuilderFactory $pqbFactory, ProductQueryBuilder $pqb, StepExecution $stepExecution, Cursor $cursor, ProductInterface $product, EntityRepository $customEntityRepository) { $jobRepository->getJobManager()->willReturn($entityManager); $stepExecution->getJobExecution()->willReturn($jobExecution); $customEntityRepository->findOneBy(['code' => 'update_product_value'])->willReturn($jobInstance); $jobInstance->getJobExecutions()->willReturn(new ArrayCollection([$jobExecution])); $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration); $pqbFactory->create()->willReturn($pqb); $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => []])); $pqb->execute()->willReturn($cursor); $cursor->next()->shouldBeCalled(); $stepExecution->incrementSummaryInfo('read')->shouldBeCalledTimes(1); $this->setStepExecution($stepExecution); $cursor->current()->willReturn($product); $this->read()->shouldReturn($product); }
/** * Sets errors on items * * @param array $item * @param array $errors * * @throws InvalidItemException */ protected function setItemErrors(array $item, array $errors) { if ($this->stepExecution) { $this->stepExecution->incrementSummaryInfo('skip'); } throw new InvalidItemException(implode("\n", $this->getErrorMessages($errors)), $item); }
/** * {@inheritdoc} */ public function read() { $this->documentManager->clear(); if (!$this->executed) { $this->executed = true; if (!is_object($this->channel)) { $this->channel = $this->channelManager->getChannelByCode($this->channel); } if ($this->missingCompleteness) { $this->completenessManager->generateMissingForChannel($this->channel); } $this->query = $this->repository->buildByChannelAndCompleteness($this->channel)->getQuery(); $this->products = $this->getQuery()->execute(); // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is) // as long as getNext() hasn't be called $this->products->getNext(); } $result = $this->products->current(); if ($result) { $this->metricConverter->convert($result, $this->channel); $this->stepExecution->incrementSummaryInfo('read'); $this->products->next(); } return $result; }
/** * @dataProvider readItemDatesDataProvider * * @param string $dateInContext * @param string $dateInItem * @param string $expectedDate * @param boolean $hasData * @param string $dateInIterator */ public function testRead($dateInContext, $dateInItem, $expectedDate, $hasData = true, $dateInIterator = null) { $iteratorMock = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Iterator\\UpdatedLoaderInterface'); $connector = $this->getConnector($this->transportMock, $this->stepExecutionMock); $this->transportMock->expects($this->at(0))->method($this->getIteratorGetterMethodName())->will($this->returnValue($iteratorMock)); $connector->setStepExecution($this->stepExecutionMock); $context = $this->stepExecutionMock->getExecutionContext(); $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, ['lastSyncItemDate' => $dateInContext]); $testValue = ['created_at' => '01.01.2200 14:15:08', 'updatedAt' => $dateInItem]; if ($hasData) { $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, ['lastSyncItemDate' => $dateInContext]); $iteratorMock->expects($this->once())->method('rewind'); $iteratorMock->expects($this->once())->method('next'); $iteratorMock->expects($this->any())->method('valid')->will($this->onConsecutiveCalls(true, false)); $iteratorMock->expects($this->once())->method('current')->will($this->returnValue($testValue)); $this->assertEquals($testValue, $connector->read()); } else { $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, ['lastSyncItemDate' => $dateInIterator]); $iteratorMock->expects($this->once())->method('rewind'); $iteratorMock->expects($this->never())->method('next'); $iteratorMock->expects($this->any())->method('valid')->will($this->returnValue(false)); $iteratorMock->expects($this->never())->method('current')->will($this->returnValue(null)); $iteratorMock->expects($this->at(0))->method('getStartDate')->will($this->returnValue(new \Datetime($dateInIterator))); $iteratorMock->expects($this->at(1))->method('getStartDate')->will($this->returnValue($dateInIterator)); } $this->assertNull($connector->read()); $connectorData = $context->get(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY); $this->assertArrayHasKey('lastSyncItemDate', $connectorData); if ($hasData) { $this->assertSame($expectedDate, $connectorData['lastSyncItemDate']); } else { $this->assertSame($dateInIterator, $connectorData['lastSyncItemDate']); } }
/** * {@inheritdoc} */ public function removeOption($name) { if ($this->hasOption($name)) { $configuration = $this->getConfiguration(); unset($configuration[$name]); $this->stepExecution->getJobExecution()->getJobInstance()->setRawConfiguration($configuration); } }
/** * @param ProductInterface $product */ protected function incrementCount(ProductInterface $product) { if ($product->getId()) { $this->stepExecution->incrementSummaryInfo('process'); } else { $this->stepExecution->incrementSummaryInfo('create'); } }