Skip to content

Commit ddeb43e

Browse files
committed
GraphQL-594,595,600:code refactored for the integretaion tests
1 parent af4b044 commit ddeb43e

File tree

3 files changed

+46
-135
lines changed

3 files changed

+46
-135
lines changed
Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,45 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Framework\App\Request\Http;
13-
use Magento\Framework\EntityManager\MetadataPool;
14-
use Magento\Framework\Serialize\SerializerInterface;
15-
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\GraphQl\Controller\GraphQl;
14+
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
1615

1716
/**
1817
* Tests cache debug headers and cache tag validation for a category with product query
1918
*
2019
* @magentoAppArea graphql
20+
* @magentoCache full_page enabled
2121
* @magentoDbIsolation disabled
22-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2322
*/
24-
class CategoriesWithProductsDispatchTest extends \Magento\TestFramework\Indexer\TestCase
23+
class CategoriesWithProductsCacheTest extends AbstractGraphqlCacheTest
2524
{
26-
const CONTENT_TYPE = 'application/json';
27-
28-
/** @var \Magento\Framework\ObjectManagerInterface */
29-
private $objectManager;
30-
31-
/** @var GraphQl */
32-
private $graphql;
33-
34-
/** @var SerializerInterface */
35-
private $jsonSerializer;
36-
37-
/** @var MetadataPool */
38-
private $metadataPool;
39-
40-
/** @var Http */
41-
private $request;
42-
4325
/**
44-
* @inheritdoc
26+
* @var GraphQl
4527
*/
46-
public static function setUpBeforeClass()
47-
{
48-
$db = Bootstrap::getInstance()->getBootstrap()
49-
->getApplication()
50-
->getDbInstance();
51-
if (!$db->isDbDumpExists()) {
52-
throw new \LogicException('DB dump does not exist.');
53-
}
54-
$db->restoreFromDbDump();
28+
private $graphqlController;
5529

56-
parent::setUpBeforeClass();
57-
}
30+
/**
31+
* @var Http
32+
*/
33+
private $request;
5834

5935
/**
6036
* @inheritdoc
6137
*/
6238
protected function setUp(): void
6339
{
64-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
65-
$this->graphql = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
66-
$this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
67-
$this->metadataPool = $this->objectManager->get(MetadataPool::class);
68-
$this->request = $this->objectManager->get(Http::class);
40+
parent::setUp();
41+
$this->graphqlController = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
42+
$this->request = $this->objectManager->create(Http::class);
6943
}
70-
7144
/**
7245
* Test cache tags and debug header for category with products querying for products and category
7346
*
7447
* @magentoCache all enabled
7548
* @magentoDataFixture Magento/Catalog/_files/category_product.php
7649
*
7750
*/
78-
public function testDispatchForCacheHeadersAndCacheTagsForCategoryWtihProducts(): void
51+
public function testToCheckRequestCacheTagsForCategoryWithProducts(): void
7952
{
8053
/** @var ProductRepositoryInterface $productRepository */
8154
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
@@ -124,12 +97,9 @@ public function testDispatchForCacheHeadersAndCacheTagsForCategoryWtihProducts()
12497
$this->request->setMethod('GET');
12598
$this->request->setParams($queryParams);
12699
/** @var \Magento\Framework\Controller\Result\Json $result */
127-
$result = $this->graphql->dispatch($this->request);
100+
$result = $this->graphqlController->dispatch($this->request);
128101
/** @var \Magento\Framework\App\Response\Http $response */
129102
$response = $this->objectManager->get(\Magento\Framework\App\Response\Http::class);
130-
/** @var $registry \Magento\Framework\Registry */
131-
$registry = $this->objectManager->get(\Magento\Framework\Registry::class);
132-
$registry->register('use_page_cache_plugin', true, true);
133103
$result->renderResult($response);
134104
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
135105
$expectedCacheTags = ['cat_c','cat_c_' . $categoryId,'cat_p','cat_p_' . $product->getId(),'FPC'];

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/CategoryDispatchTest.php renamed to dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/CategoryCacheTest.php

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,45 @@
88
namespace Magento\GraphQlCache\Controller\Catalog;
99

1010
use Magento\Framework\App\Request\Http;
11-
use Magento\Framework\EntityManager\MetadataPool;
12-
use Magento\Framework\Serialize\SerializerInterface;
13-
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\GraphQl\Controller\GraphQl;
12+
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
1413

1514
/**
1615
* Tests cache debug headers and cache tag validation for a simple category query
1716
*
1817
* @magentoAppArea graphql
18+
* @magentoCache full_page enabled
1919
* @magentoDbIsolation disabled
20-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2120
*/
22-
class CategoryDispatchTest extends \Magento\TestFramework\Indexer\TestCase
21+
class CategoryCacheTest extends AbstractGraphqlCacheTest
2322
{
24-
const CONTENT_TYPE = 'application/json';
25-
26-
/** @var \Magento\Framework\ObjectManagerInterface */
27-
private $objectManager;
28-
29-
/** @var GraphQl */
30-
private $graphql;
31-
32-
/** @var SerializerInterface */
33-
private $jsonSerializer;
34-
35-
/** @var MetadataPool */
36-
private $metadataPool;
37-
38-
/** @var Http */
39-
private $request;
40-
4123
/**
42-
* @inheritdoc
24+
* @var GraphQl
4325
*/
44-
public static function setUpBeforeClass()
45-
{
46-
$db = Bootstrap::getInstance()->getBootstrap()
47-
->getApplication()
48-
->getDbInstance();
49-
if (!$db->isDbDumpExists()) {
50-
throw new \LogicException('DB dump does not exist.');
51-
}
52-
$db->restoreFromDbDump();
26+
private $graphqlController;
5327

54-
parent::setUpBeforeClass();
55-
}
28+
/**
29+
* @var Http
30+
*/
31+
private $request;
5632

5733
/**
5834
* @inheritdoc
5935
*/
6036
protected function setUp(): void
6137
{
62-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
63-
$this->graphql = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
64-
$this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
65-
$this->metadataPool = $this->objectManager->get(MetadataPool::class);
66-
$this->request = $this->objectManager->get(Http::class);
38+
parent::setUp();
39+
$this->graphqlController = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
40+
$this->request = $this->objectManager->create(Http::class);
6741
}
68-
6942
/**
7043
* Test cache tags and debug header for category and querying only for category
7144
*
7245
* @magentoCache all enabled
7346
* @magentoDataFixture Magento/Catalog/_files/category_product.php
7447
*
7548
*/
76-
public function testDispatchForCacheDebugHeadersAndCacheTagsForCategory(): void
49+
public function testToCheckRequestCacheTagsForForCategory(): void
7750
{
7851
$categoryId ='333';
7952
$query
@@ -92,12 +65,10 @@ public function testDispatchForCacheDebugHeadersAndCacheTagsForCategory(): void
9265
$this->request->setMethod('GET');
9366
$this->request->setQueryValue('query', $query);
9467
/** @var \Magento\Framework\Controller\Result\Json $result */
95-
$result = $this->graphql->dispatch($this->request);
68+
$result = $this->graphqlController->dispatch($this->request);
9669
/** @var \Magento\Framework\App\Response\Http $response */
9770
$response = $this->objectManager->get(\Magento\Framework\App\Response\Http::class);
9871
/** @var $registry \Magento\Framework\Registry */
99-
$registry = $this->objectManager->get(\Magento\Framework\Registry::class);
100-
$registry->register('use_page_cache_plugin', true, true);
10172
$result->renderResult($response);
10273
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
10374
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/ProductsDispatchTest.php renamed to dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/ProductsCacheTest.php

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,44 @@
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Framework\App\Request\Http;
12-
use Magento\Framework\EntityManager\MetadataPool;
13-
use Magento\Framework\Serialize\SerializerInterface;
14-
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\GraphQl\Controller\GraphQl;
13+
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
1514

1615
/**
1716
* Tests cache debug headers and cache tag validation for a simple product query
1817
*
1918
* @magentoAppArea graphql
19+
* @magentoCache full_page enabled
2020
* @magentoDbIsolation disabled
21-
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
22-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2321
*/
24-
class ProductsDispatchTest extends \Magento\TestFramework\Indexer\TestCase
22+
class ProductsCacheTest extends AbstractGraphqlCacheTest
2523
{
26-
const CONTENT_TYPE = 'application/json';
27-
28-
/** @var \Magento\Framework\ObjectManagerInterface */
29-
private $objectManager;
30-
31-
/** @var GraphQl */
32-
private $graphql;
33-
34-
/** @var SerializerInterface */
35-
private $jsonSerializer;
36-
37-
/** @var MetadataPool */
38-
private $metadataPool;
39-
40-
/** @var Http */
41-
private $request;
42-
4324
/**
44-
* @inheritdoc
25+
* @var GraphQl
4526
*/
46-
public static function setUpBeforeClass()
47-
{
48-
$db = Bootstrap::getInstance()->getBootstrap()
49-
->getApplication()
50-
->getDbInstance();
51-
if (!$db->isDbDumpExists()) {
52-
throw new \LogicException('DB dump does not exist.');
53-
}
54-
$db->restoreFromDbDump();
27+
private $graphqlController;
5528

56-
parent::setUpBeforeClass();
57-
}
29+
/**
30+
* @var Http
31+
*/
32+
private $request;
5833

5934
/**
6035
* @inheritdoc
6136
*/
6237
protected function setUp(): void
6338
{
64-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
65-
$this->graphql = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
66-
$this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
67-
$this->metadataPool = $this->objectManager->get(MetadataPool::class);
68-
$this->request = $this->objectManager->get(Http::class);
39+
parent::setUp();
40+
$this->graphqlController = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
41+
$this->request = $this->objectManager->create(Http::class);
6942
}
70-
7143
/**
7244
* Test request is dispatched and response is checked for debug headers and cache tags
7345
*
7446
* @magentoCache all enabled
75-
* @return void
47+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
7648
*/
77-
public function testDispatchWithGetForCacheDebugHeadersAndCacheTagsForProducts(): void
49+
public function testToCheckRequestCacheTagsForProducts(): void
7850
{
7951
/** @var ProductRepositoryInterface $productRepository */
8052
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
@@ -103,12 +75,10 @@ public function testDispatchWithGetForCacheDebugHeadersAndCacheTagsForProducts()
10375
$this->request->setMethod('GET');
10476
$this->request->setQueryValue('query', $query);
10577
/** @var \Magento\Framework\Controller\Result\Json $result */
106-
$result = $this->graphql->dispatch($this->request);
78+
$result = $this->graphqlController->dispatch($this->request);
10779
/** @var \Magento\Framework\App\Response\Http $response */
10880
$response = $this->objectManager->get(\Magento\Framework\App\Response\Http::class);
10981
/** @var $registry \Magento\Framework\Registry */
110-
$registry = $this->objectManager->get(\Magento\Framework\Registry::class);
111-
$registry->register('use_page_cache_plugin', true, true);
11282
$result->renderResult($response);
11383
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
11484
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());

0 commit comments

Comments
 (0)