/**
  * @return Channel
  */
 protected function getChannel()
 {
     if ($this->channel === null || $this->context->getOption('channel') !== $this->channel->getId()) {
         $this->channel = $this->connectorContextMediator->getChannel($this->context);
     }
     return $this->channel;
 }
 public function testProcessGoodScenario()
 {
     $testWebsiteId = 1;
     $testStoreId = 2;
     $testStoresArray = new \ArrayIterator([['website_id' => $testWebsiteId, 'store_id' => $testStoreId]]);
     $settingBag = new ParameterBag(['website_id' => $testWebsiteId]);
     $testData = [['id' => 1, 'originId' => 11], ['id' => 2, 'originId' => 22], ['id' => 3, 'originId' => 33]];
     $testExistedCarts = [(object) ['entity_id' => 22]];
     $repo = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\CartRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getRepository')->with('OroCRMMagentoBundle:Cart')->will($this->returnValue($repo));
     $transport = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport')->setMethods(['getSettingsBag'])->getMockForAbstractClass();
     $transport->expects($this->any())->method('getSettingsBag')->will($this->returnValue($settingBag));
     $realTransport = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface');
     $realTransport->expects($this->once())->method('isSupportedExtensionVersion')->will($this->returnValue(true));
     $realTransport->expects($this->once())->method('getStores')->will($this->returnValue($testStoresArray));
     $this->helper->expects($this->once())->method('getTransport')->will($this->returnValue($realTransport));
     $channel = new Channel();
     $channel->setTransport($transport);
     $realTransport->expects($this->at(3))->method('call')->with(SoapTransport::ACTION_ORO_CART_LIST, ['filters' => ['complex_filter' => [['key' => 'store_id', 'value' => ['key' => 'in', 'value' => $testStoreId]], ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => '11,22']]]], 'pager' => ['page' => 1, 'pageSize' => self::BATCH_SIZE]])->will($this->returnValue($testExistedCarts));
     $realTransport->expects($this->at(4))->method('call')->with(SoapTransport::ACTION_ORO_CART_LIST, ['filters' => ['complex_filter' => [['key' => 'store_id', 'value' => ['key' => 'in', 'value' => $testStoreId]], ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => '33']]]], 'pager' => ['page' => 1, 'pageSize' => self::BATCH_SIZE]])->will($this->returnValue([]));
     $repo->expects($this->once())->method('getCartsByChannelIdsIterator')->with($channel)->will($this->returnValue($testData));
     $repo->expects($this->at(1))->method('markExpired')->with([1]);
     $repo->expects($this->at(2))->method('markExpired')->with([3]);
     $this->processor->process($channel);
 }
 /**
  * @ TransportInterface $transport
  */
 public function initFromContext()
 {
     $this->transport = $this->contextMediator->getTransport($this->getContext(), true);
     $this->channel = $this->contextMediator->getChannel($this->getContext());
     if (!$this->transport) {
         throw new \InvalidArgumentException('Transport was not provided');
     }
     $this->transport->init($this->channel->getTransport());
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     $this->transport = $this->contextMediator->getTransport($context, true);
     $this->channel = $this->contextMediator->getChannel($context);
     $this->validateConfiguration();
     $this->transport->init($this->channel->getTransport());
     $this->setSourceIterator($this->getConnectorSource());
     if ($this->getSourceIterator() instanceof LoggerAwareInterface) {
         $this->getSourceIterator()->setLogger($this->logger);
     }
 }
 public function testGetChannelFromContext()
 {
     $testID = 1;
     $integration = new Integration();
     $integration->setTransport($this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport'));
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $context->expects($this->once())->method('getOption')->with('channel')->will($this->returnValue($testID));
     $this->repo->expects($this->once())->method('getOrLoadById')->with($testID)->will($this->returnValue($integration));
     $result = $this->contextMediator->getChannel($context);
     $this->assertEquals($integration, $result);
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     $this->channel = $this->contextMediator->getChannel($context);
     $this->transport = $this->contextMediator->getInitializedTransport($this->channel, true);
     // info was loaded from index action
     if ($this->transport->isSupportedExtensionVersion()) {
         return;
     }
     $entitiesIds = (array) $this->stepExecution->getJobExecution()->getExecutionContext()->get($this->contextKey);
     if (!$entitiesIds) {
         return;
     }
     sort($entitiesIds);
     $this->ids = array_unique(array_filter($entitiesIds));
 }
示例#7
0
 protected function setUp()
 {
     $this->contextRegistry = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry');
     $this->logger = new LoggerStrategy(new NullLogger());
     $this->contextMediator = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Provider\\ConnectorContextMediator')->disableOriginalConstructor()->getMock();
     $this->stepExecutionMock = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock();
     $this->context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $this->contextRegistry->expects($this->any())->method('getByStepExecution')->will($this->returnValue($this->context));
     $channel = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel');
     $transportSettings = $this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $channel->expects($this->any())->method('getTransport')->will($this->returnValue($transportSettings));
     $this->transport = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface');
     $this->contextMediator->expects($this->any())->method('getInitializedTransport')->will($this->returnValue($this->transport));
     $this->contextMediator->expects($this->any())->method('getChannel')->will($this->returnValue($channel));
     $this->executionContext = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext');
     $this->jobExecution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution');
     $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($this->executionContext));
     $this->stepExecutionMock->expects($this->once())->method('getJobExecution')->will($this->returnValue($this->jobExecution));
 }
 public function testGetInitializedTransport()
 {
     $testTransport = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Provider\\TransportInterface');
     $transportEntity = $this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $integration = new Integration();
     $integration->setTransport($transportEntity);
     $this->registry->expects($this->once())->method('getTransportTypeBySettingEntity')->will($this->returnValue($testTransport));
     $testTransport->expects($this->once())->method('init')->with($transportEntity);
     $result = $this->contextMediator->getInitializedTransport($integration);
     $this->assertEquals($testTransport, $result);
     // test local cache
     $this->contextMediator->getInitializedTransport($integration);
 }
示例#9
0
 /**
  * Configure processor
  *
  * @param Channel $channel
  *
  * @throws \LogicException
  */
 protected function configure(Channel $channel)
 {
     /** @var SoapTransport $transport */
     $transport = $this->helper->getTransport($channel);
     $transport->init($channel->getTransport());
     /** @var ParameterBag $settings */
     $settings = $channel->getTransport()->getSettingsBag();
     if (!$transport->isSupportedExtensionVersion()) {
         throw new ExtensionRequiredException();
     }
     $websiteId = $settings->get('website_id');
     $stores = $this->getSores($transport, $websiteId);
     if (empty($stores)) {
         throw new \LogicException(sprintf('Could not resolve store dependency for website id: %d', $websiteId));
     }
     $this->transport = $transport;
     $this->stores = $stores;
 }
示例#10
0
 /**
  * Configure processor
  *
  * @param Channel $channel
  *
  * @throws \LogicException
  */
 protected function configure(Channel $channel)
 {
     $transport = $this->helper->getTransport($channel);
     $transport->init($channel->getTransport());
     $settings = $channel->getTransport()->getSettingsBag();
     if (!$transport->isExtensionInstalled()) {
         throw new ExtensionRequiredException();
     }
     $websiteId = $settings->get('website_id');
     $stores = [];
     $magentoStores = iterator_to_array($transport->getStores());
     foreach ($magentoStores as $store) {
         if ($store['website_id'] == $websiteId) {
             $stores[] = $store['store_id'];
         }
     }
     if (empty($stores)) {
         throw new \LogicException(sprintf('Could not resolve store dependency for website id: %d', $websiteId));
     }
     $this->transport = $transport;
     $this->stores = $stores;
 }