Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductOnlyXLeftInStockTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
13 {
18  {
19  $this->cleanCache();
20  $productSku = 'simple';
21 
22  $query = <<<QUERY
23  {
24  products(filter: {sku: {eq: "{$productSku}"}})
25  {
26  items {
27  only_x_left_in_stock
28  }
29  }
30  }
31 QUERY;
32 
33  $response = $this->graphQlQuery($query);
34 
35  $this->assertArrayHasKey(0, $response['products']['items']);
36  $this->assertArrayHasKey('only_x_left_in_stock', $response['products']['items'][0]);
37  $this->assertNull($response['products']['items'][0]['only_x_left_in_stock']);
38  }
39 
45  {
46  $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');
47  $productSku = 'simple';
48 
49  $query = <<<QUERY
50  {
51  products(filter: {sku: {eq: "{$productSku}"}})
52  {
53  items {
54  only_x_left_in_stock
55  }
56  }
57  }
58 QUERY;
59  $response = $this->graphQlQuery($query);
60 
61  $this->assertArrayHasKey(0, $response['products']['items']);
62  $this->assertArrayHasKey('only_x_left_in_stock', $response['products']['items'][0]);
63  $this->assertEquals(100, $response['products']['items'][0]['only_x_left_in_stock']);
64  }
65 }
$response
Definition: 404.php:11
graphQlQuery(string $query, array $variables=[], string $operationName='', array $headers=[])