public function testValidateClientWebhook() { $data = $this->client->getIncomingWebhook(TRUE, $this->data, $this->hmac_header); $this->assertNotEmpty($data, 'Webhook error.'); $this->assertObjectHasAttribute('test', $data); $this->assertEquals('this is a test', $data->test, 'Data has changed.'); }
/** * @param StoreEntity $store * @return Client */ public function createClient(StoreEntity $store) { $client = new Client(array("shopUrl" => $store->getShopifyStoreUrl(), "X-Shopify-Access-Token" => $store->getShopifyAccessToken())); $loggerName = sprintf('shopify_%s', str_replace(' ', '_', strtolower($store->getStoreLabel()))); $loggerPath = sprintf('%s/%s.log', $this->logPath, $loggerName); $log = new Logger($loggerName); $log->pushHandler(new StreamHandler($loggerPath, $this->logLevel)); $subscriber = new LogSubscriber($log); $client->getEmitter()->attach($subscriber); return $client; }
public function testShopGetInfo() { $response = $this->client->get('shop'); $this->assertObjectHasAttribute('shop', $response); $shop = $response->shop; $this->assertObjectHasAttribute('domain', $shop); $this->assertObjectHasAttribute('myshopify_domain', $shop); $this->assertObjectHasAttribute('email', $shop); $this->assertObjectHasAttribute('name', $shop); $this->assertNotEmpty($shop->domain); $this->assertNotEmpty($shop->myshopify_domain); $this->assertNotEmpty($shop->email); $this->assertNotEmpty($shop->name); }
/** * @depends testProductDelete */ public function testProductPagination() { for ($i = 0; $i <= 9; $i++) { $this->client->createProduct(['title' => 'test product ' . $i]); } $counter = 0; foreach ($this->client->getResourcePager('products', 5) as $product) { $this->assertNotEmpty($product); $this->assertObjectHasAttribute('title', $product); $this->assertEquals('test product ' . $counter, $product->title); $counter++; } $this->assertEquals(10, $this->client->getProductsCount(), 'There should be 10 products in the system.'); $opts['query']['limit'] = 5; foreach ($this->client->getProducts($opts) as $product) { $this->assertObjectHasAttribute('id', $product); $this->client->deleteProduct($product->id); } $this->assertEquals(0, $this->client->getProductsCount(), 'Not all products were deleted.'); }
/** * @param StoreEntity $store * @param ShopifyOrderEntity $order * @return ShopifyTransactionEntity|null */ public function getTransaction(StoreEntity $store, ShopifyOrderEntity $order) { $this->setSettings($store); $response = $this->client->getTransactions(['order_id' => $order->getId()]); $orderTransaction = null; if ($response['transactions']) { foreach ($response['transactions'] as $transaction) { if ($transaction['kind'] == ShopifyTransactionEntity::KIND_AUTHORIZATION || $transaction['kind'] == ShopifyTransactionEntity::KIND_CAPTURE) { $orderTransaction = ShopifyTransactionEntity::createFromTransactionResponse($transaction); $order->setTransaction($orderTransaction); break; } } } }
public function mockShopifyApiClient(KernelInterface $kernel) { $shopClientFactory = $this->getMockBuilder('\\ERPBundle\\Factory\\Client\\ShopifyApiClientFactory')->disableOriginalConstructor()->getMock(); $shopifyApiClient = new ShopifyClient(array("shopUrl" => 'myStore', "X-Shopify-Access-Token" => 'MyAccessToken')); $mock = new Mock(); $shopifyApiClient->getEmitter()->attach($mock); $shopClientFactory->expects($this->any())->method('createClient')->willReturn($shopifyApiClient); $kernel->getContainer()->set('erp.guzzle.client.shopify', $shopClientFactory); return $mock; }