Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductStockStatusTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
16 {
20  private $stockRegistry;
21 
22  protected function setUp()
23  {
24  $this->stockRegistry = Bootstrap::getObjectManager()->create(StockRegistryInterface::class);
25  }
26 
31  {
32  $productSku = 'simple';
33 
34  $query = <<<QUERY
35  {
36  products(filter: {sku: {eq: "{$productSku}"}})
37  {
38  items {
39  stock_status
40  }
41  }
42  }
43 QUERY;
44 
45  $response = $this->graphQlQuery($query);
46 
47  $this->assertArrayHasKey(0, $response['products']['items']);
48  $this->assertArrayHasKey('stock_status', $response['products']['items'][0]);
49  $this->assertEquals('IN_STOCK', $response['products']['items'][0]['stock_status']);
50  }
51 
57  {
58  $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');
59  $productSku = 'simple';
60 
61  $query = <<<QUERY
62  {
63  products(filter: {sku: {eq: "{$productSku}"}})
64  {
65  items {
66  stock_status
67  }
68  }
69  }
70 QUERY;
71 
72  $stockItem = $this->stockRegistry->getStockItemBySku($productSku);
73  $stockItem->setQty(0);
74  $this->stockRegistry->updateStockItemBySku($productSku, $stockItem);
75 
76  $response = $this->graphQlQuery($query);
77 
78  $this->assertArrayHasKey(0, $response['products']['items']);
79  $this->assertArrayHasKey('stock_status', $response['products']['items'][0]);
80  $this->assertEquals('OUT_OF_STOCK', $response['products']['items'][0]['stock_status']);
81  }
82 }
$response
Definition: 404.php:11
graphQlQuery(string $query, array $variables=[], string $operationName='', array $headers=[])