Skip to content

Commit a848158

Browse files
committed
B2B-2659: Implement GraphQL Resolver Cache for cmsBlocks query
1 parent 2f90448 commit a848158

File tree

3 files changed

+65
-36
lines changed

3 files changed

+65
-36
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestFramework\TestCase\GraphQl;
9+
10+
use Magento\Framework\App\Cache\StateInterface as CacheStateInterface;
11+
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlResolverCache;
12+
use Magento\TestFramework\TestCase\GraphQlAbstract;
13+
14+
class ResolverCacheAbstract extends GraphQlAbstract
15+
{
16+
/**
17+
* @var GraphQlResolverCache
18+
*/
19+
private $graphQlResolverCache;
20+
21+
/**
22+
* @var CacheStateInterface
23+
*/
24+
private $cacheState;
25+
26+
/**
27+
* @var bool
28+
*/
29+
private $originalCacheStateEnabledStatus;
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
protected function setUp(): void
35+
{
36+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
37+
$this->cacheState = $objectManager->get(CacheStateInterface::class);
38+
$this->originalCacheStateEnabledStatus = $this->cacheState->isEnabled(GraphQlResolverCache::TYPE_IDENTIFIER);
39+
$this->cacheState->setEnabled(GraphQlResolverCache::TYPE_IDENTIFIER, true);
40+
$this->graphQlResolverCache = $objectManager->get(GraphQlResolverCache::class);
41+
42+
parent::setUp();
43+
}
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
protected function tearDown(): void
49+
{
50+
// clean graphql resolver cache and reset to original enablement status
51+
$this->graphQlResolverCache->clean();
52+
$this->cacheState->setEnabled(
53+
GraphQlResolverCache::TYPE_IDENTIFIER,
54+
$this->originalCacheStateEnabledStatus
55+
);
56+
57+
parent::tearDown();
58+
}
59+
}

dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/BlockTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
1515
use Magento\Store\Model\StoreManagerInterface;
1616
use Magento\TestFramework\ObjectManager;
17+
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
1718
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
18-
use Magento\TestFramework\TestCase\GraphQlAbstract;
1919
use Magento\Widget\Model\Template\FilterEmulate;
2020

21-
class BlockTest extends GraphQlAbstract
21+
class BlockTest extends ResolverCacheAbstract
2222
{
2323
/**
2424
* @var BlockRepositoryInterface
@@ -47,13 +47,8 @@ protected function setUp(): void
4747
$this->graphQlResolverCache = $objectManager->get(GraphQlResolverCache::class);
4848
$this->widgetFilter = $objectManager->get(FilterEmulate::class);
4949
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
50-
}
51-
52-
protected function tearDown(): void
53-
{
54-
$this->graphQlResolverCache->clean();
5550

56-
parent::tearDown();
51+
parent::setUp();
5752
}
5853

5954
/**

dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/PageTest.php

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
use Magento\Cms\Model\PageRepository;
1313
use Magento\Framework\Api\SearchCriteriaBuilder;
1414
use Magento\Framework\App\Cache\Frontend\Factory as CacheFrontendFactory;
15-
use Magento\Framework\App\Cache\StateInterface as CacheState;
1615
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlResolverCache;
1716
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
1817
use Magento\Integration\Api\CustomerTokenServiceInterface;
1918
use Magento\Store\Model\StoreManagerInterface;
2019
use Magento\TestFramework\ObjectManager;
20+
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
2121
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
22-
use Magento\TestFramework\TestCase\GraphQlAbstract;
2322

2423
/**
2524
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2625
*/
27-
class PageTest extends GraphQlAbstract
26+
class PageTest extends ResolverCacheAbstract
2827
{
2928
/**
3029
* @var GraphQlResolverCache
@@ -46,21 +45,11 @@ class PageTest extends GraphQlAbstract
4645
*/
4746
private $customerTokenService;
4847

49-
/**
50-
* @var CacheState
51-
*/
52-
private $cacheState;
53-
5448
/**
5549
* @var StoreManagerInterface
5650
*/
5751
private $storeManager;
5852

59-
/**
60-
* @var bool
61-
*/
62-
private $originalCacheStateEnabledStatus;
63-
6453
protected function setUp(): void
6554
{
6655
$objectManager = ObjectManager::getInstance();
@@ -71,21 +60,7 @@ protected function setUp(): void
7160
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
7261
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
7362

74-
$this->cacheState = $objectManager->get(CacheState::class);
75-
$this->originalCacheStateEnabledStatus = $this->cacheState->isEnabled(GraphQlResolverCache::TYPE_IDENTIFIER);
76-
$this->cacheState->setEnabled(GraphQlResolverCache::TYPE_IDENTIFIER, true);
77-
}
78-
79-
protected function tearDown(): void
80-
{
81-
// clean graphql resolver cache and reset to original enablement status
82-
$this->graphQlResolverCache->clean();
83-
$this->cacheState->setEnabled(
84-
GraphQlResolverCache::TYPE_IDENTIFIER,
85-
$this->originalCacheStateEnabledStatus
86-
);
87-
88-
parent::tearDown();
63+
parent::setUp();
8964
}
9065

9166
/**

0 commit comments

Comments
 (0)