asyncBus = $this->get('async_bus'); } public function getDataSet() { return $this->getJsonDataSetFromFile(); } protected $PohodaConnector; /** * @var TransformHelper */ protected $transformHelper; protected function setEnvironment() { $this->PohodaConnector = ServiceContainer::getService(PohodaConnector::class); $this->transformHelper = ServiceContainer::getService(TransformHelper::class); $this->getLogger(); $this->prepareMServer(); } public function testGetBaseOrdersXML() { $this->setEnvironment(); $ordersOut = $this->get(OrderExporter::class); $ordersOutXML = $ordersOut->getXML([4047]); $this->assertXmlStringEqualsXmlFile(__DIR__.'/ExportBaseOrder.xml', $ordersOutXML); } public function testGetPohodaBaseOrdersXML() { $this->setEnvironment(); $ordersOut = $this->get(PohodaOrderExporter::class); $ordersOutXML = $ordersOut->getXML([4047]); $this->assertXmlStringEqualsXmlFile(__DIR__.'/ExportPohodaBaseOrder.xml', $ordersOutXML); } public function testTransformShopOrder() { $this->setEnvironment(); $ordersOut = $this->get(PohodaOrderExporter::class); $ordersOutXML = $ordersOut->getXML([4047]); $ordersOutXML = $this->transformHelper->baseTransform($ordersOutXML, $this->transformHelper->loadXslt('ordersOut.xsl')); $this->assertXmlStringEqualsXmlFile(__DIR__.'/ExportOrders.xml', $ordersOutXML->saveXML()); } public function testOrderExportResponse() { $this->setEnvironment(); $this->ordersOut = $this->get(OrdersExporter::class); $xml = file_get_contents(__DIR__.'/ExportOrdersResponse.xml'); $this->ordersOut->processResponse($xml); $response = simplexml_load_string($xml); $logData = null; foreach ($response->xpath('rsp:responsePackItem') as $responsePackItem) { $logData = $responsePackItem->asXML(); } $testHandler = $this->getTestHandler(); $this->assertEquals(true, $testHandler->hasNoticeThatContains('POHODA RESPONSE: Order Export')); foreach ($testHandler->getRecords() as $record) { if ($record['message'] == 'POHODA RESPONSE: Order Export') { $this->assertEquals($logData, $record['context']['data']); } } $qb = sqlQueryBuilder() ->select('*') ->from('order_items') ->andWhere(Operator::equals(['id' => '31011'])) ->execute() ->fetch(); $this->assertEquals('965136', $qb['pohoda_id']); } public function testAsyncExportOrder() { $instance = $this->autowire(PohodaConnectorMock::class); $this->set(PohodaConnector::class, $instance); $cfg = \KupShop\KupShopBundle\Config::get(); $cfg['Modules']['pohoda']['create_corrective_invoice_from_returns'] = true; $cfg['Modules']['pohoda']['instant_order_upload'] = true; $this->prepareMServer(); $asyncMessage = new OrderMessage(); $asyncMessage->setIdOrder(4048); $result = $this->getHandledResult($this->asyncBus->dispatch($asyncMessage)); $qb = sqlQueryBuilder() ->select('*') ->from('orders_pohoda_invoices') ->andWhere(Operator::equals(['id_order' => '4048'])) ->sendToMaster() ->execute() ->fetchAssociative(); $this->assertEquals('62910', $qb['id_pohoda_invoice']); $this->assertTrue($result['status']); } public function getHandledResult(Envelope $envelope) { $stamp = $envelope->last(HandledStamp::class); return $stamp->getResult(); } } class PohodaConnectorMock extends PohodaConnector { public function sendRequest($XmlBodyRequest) { $request = new \SimpleXMLElement($XmlBodyRequest); $request->registerXPathNamespace('ord', 'ord:order'); $request->registerXPathNamespace('inv', 'inv:invoice'); if (!empty($request->xpath('dat:dataPackItem/ord:order/ord:orderHeader/ord:orderType'))) { return ' 272939 0194048 add add 31011 965136 add 31012 965137 '; } if (!empty($request->xpath('dat:dataPackItem/inv:invoice/inv:invoiceHeader/inv:invoiceType'))) { return ' 62910 2300104752 link '; } } }