Skip to content

Commit 7dcdf5e

Browse files
author
Andrey Konosov
committed
MAGETWO-58265: [Github][Cloud][Customer]Fix Varnish X-Header
- Stabilization fixes
1 parent dd24942 commit 7dcdf5e

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Cache/Tag/ConfigurableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Framework\App\Test\Unit\Model\Product\Cache\Tag;
7+
namespace Magento\ConfigurableProduct\Test\Unit\Model\Product\Cache\Tag;
88

99
use \Magento\ConfigurableProduct\Model\Product\Cache\Tag\Configurable;
1010

app/code/Magento/PageCache/Observer/FlushCacheByTags.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class FlushCacheByTags implements ObserverInterface
3030
*/
3131
private $fullPageCache;
3232

33+
/**
34+
* Invalidation tags resolver
35+
*
36+
* @var \Magento\Framework\App\Cache\Tag\Resolver
37+
*/
38+
private $tagResolver;
39+
3340
/**
3441
* @param \Magento\PageCache\Model\Config $config
3542
* @param \Magento\Framework\App\PageCache\Cache $cache
@@ -49,12 +56,11 @@ public function __construct(\Magento\PageCache\Model\Config $config, \Magento\Fr
4956
*/
5057
public function execute(\Magento\Framework\Event\Observer $observer)
5158
{
52-
$object = $observer->getEvent()->getObject();
53-
if (!is_object($object)) {
54-
return;
55-
}
56-
5759
if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) {
60+
$object = $observer->getEvent()->getObject();
61+
if (!is_object($object)) {
62+
return;
63+
}
5864
$tags = $this->getTagResolver()->getTags($object);
5965

6066
if (!empty($tags)) {
@@ -83,6 +89,10 @@ private function getCache()
8389
*/
8490
private function getTagResolver()
8591
{
86-
return ObjectManager::getInstance()->get(\Magento\Framework\App\Cache\Tag\Resolver::class);
92+
if ($this->tagResolver === null) {
93+
$this->tagResolver = \Magento\Framework\App\ObjectManager::getInstance()
94+
->get(\Magento\Framework\App\Cache\Tag\Resolver::class);
95+
}
96+
return $this->tagResolver;
8797
}
8898
}

app/code/Magento/PageCache/Test/Unit/Observer/FlushCacheByTagsTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ class FlushCacheByTagsTest extends \PHPUnit_Framework_TestCase
2323
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\PageCache\Model\Cache\Type */
2424
private $fullPageCacheMock;
2525

26+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Cache\Tag\Resolver */
27+
private $tagResolver;
28+
2629
/**
2730
* Set up all mocks and data for test
2831
*/
2932
protected function setUp()
3033
{
34+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3135
$this->_configMock = $this->getMock(
3236
\Magento\PageCache\Model\Config::class,
3337
['getType', 'isEnabled'],
@@ -42,6 +46,11 @@ protected function setUp()
4246
$this->_configMock,
4347
$this->_cacheMock
4448
);
49+
50+
$this->tagResolver = $this->getMock(\Magento\Framework\App\Cache\Tag\Resolver::class, [], [], '', false);
51+
52+
53+
$helper->setBackwardCompatibleProperty($this->_model, 'tagResolver', $this->tagResolver);
4554
$reflection = new \ReflectionClass(\Magento\PageCache\Observer\FlushCacheByTags::class);
4655
$reflectionProperty = $reflection->getProperty('fullPageCache');
4756
$reflectionProperty->setAccessible(true);
@@ -70,7 +79,7 @@ public function testExecute($cacheState)
7079
$this->_configMock->expects($this->once())
7180
->method('getType')
7281
->willReturn(\Magento\PageCache\Model\Config::BUILT_IN);
73-
$observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
82+
$this->tagResolver->expects($this->once())->method('getTags')->will($this->returnValue($tags));
7483

7584
$this->fullPageCacheMock->expects($this->once())
7685
->method('clean')
@@ -106,7 +115,7 @@ public function testExecuteWithEmptyTags()
106115
)->will(
107116
$this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)
108117
);
109-
$observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
118+
$this->tagResolver->expects($this->once())->method('getTags')->will($this->returnValue($tags));
110119

111120
$this->fullPageCacheMock->expects($this->never())->method('clean');
112121

0 commit comments

Comments
 (0)