Skip to content

Commit dd24942

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

File tree

8 files changed

+59
-14
lines changed

8 files changed

+59
-14
lines changed

app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InvalidateVarnishObserver implements ObserverInterface
2525
/**
2626
* Invalidation tags resolver
2727
*
28-
* @var \Magento\PageCache\Model\Cache\Tag\Resolver
28+
* @var \Magento\Framework\App\Cache\Tag\Resolver
2929
*/
3030
private $tagResolver;
3131

@@ -39,7 +39,6 @@ public function __construct(
3939
) {
4040
$this->config = $config;
4141
$this->purgeCache = $purgeCache;
42-
$this->tagResolver = $this->getTagResolver();
4342
}
4443

4544
/**
@@ -56,7 +55,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5655
return;
5756
}
5857
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
59-
$bareTags = $this->tagResolver->getTags($object);
58+
$bareTags = $this->getTagResolver()->getTags($object);
6059

6160
$tags = [];
6261
$pattern = "((^|,)%s(,|$))";
@@ -76,6 +75,10 @@ public function execute(\Magento\Framework\Event\Observer $observer)
7675
*/
7776
private function getTagResolver()
7877
{
79-
return ObjectManager::getInstance()->get(\Magento\Framework\App\Cache\Tag\Resolver::class);
78+
if ($this->tagResolver === null) {
79+
$this->tagResolver = \Magento\Framework\App\ObjectManager::getInstance()
80+
->get(\Magento\Framework\App\Cache\Tag\Resolver::class);
81+
}
82+
return $this->tagResolver;
8083
}
8184
}

app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CacheInvalidate\Test\Unit\Observer;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
810
class InvalidateVarnishObserverTest extends \PHPUnit_Framework_TestCase
911
{
1012
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver */
@@ -22,11 +24,16 @@ class InvalidateVarnishObserverTest extends \PHPUnit_Framework_TestCase
2224
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\DataObject\ */
2325
protected $observerObject;
2426

27+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Tag\Resolver */
28+
private $tagResolver;
29+
2530
/**
2631
* Set up all mocks and data for test
2732
*/
2833
protected function setUp()
2934
{
35+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36+
3037
$this->configMock = $this->getMock(
3138
\Magento\PageCache\Model\Config::class,
3239
['getType', 'isEnabled'],
@@ -39,6 +46,10 @@ protected function setUp()
3946
$this->configMock,
4047
$this->purgeCache
4148
);
49+
50+
$this->tagResolver = $this->getMock(\Magento\Framework\App\Cache\Tag\Resolver::class, [], [], '', false);
51+
$helper->setBackwardCompatibleProperty($this->model, 'tagResolver', $this->tagResolver);
52+
4253
$this->observerMock = $this->getMock(
4354
\Magento\Framework\Event\Observer::class,
4455
['getEvent'],
@@ -65,10 +76,12 @@ public function testInvalidateVarnish()
6576
)->will(
6677
$this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
6778
);
79+
6880
$eventMock = $this->getMock(\Magento\Framework\Event::class, ['getObject'], [], '', false);
6981
$eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->observerObject));
7082
$this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
71-
$this->observerObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
83+
$this->tagResolver->expects($this->once())->method('getTags')->with($this->observerObject)
84+
->will($this->returnValue($tags));
7285
$this->purgeCache->expects($this->once())->method('sendPurgeRequest')->with($pattern);
7386

7487
$this->model->execute($this->observerMock);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66

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

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

1111
class ConfigurableTest extends \PHPUnit_Framework_TestCase
1212
{
1313

1414
/**
15-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable
15+
* @var \PHPUnit_Framework_MockObject_MockObject|Configurable
1616
*/
1717
private $typeResource;
1818

@@ -24,7 +24,11 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
2424
protected function setUp()
2525
{
2626
$this->typeResource = $this->getMock(
27-
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class, [], [], '', false
27+
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class,
28+
[],
29+
[],
30+
'',
31+
false
2832
);
2933

3034
$this->model = new Configurable($this->typeResource);

lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class FlushCacheByTags
3737
* @param Type\FrontendPool $cachePool
3838
* @param StateInterface $cacheState
3939
* @param array $cacheList
40+
* @param Tag\Resolver $tagResolver
4041
*/
4142
public function __construct(
4243
\Magento\Framework\App\Cache\Type\FrontendPool $cachePool,

lib/internal/Magento/Framework/App/Cache/Tag/Resolver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Resolver
1717
*/
1818
private $strategyFactory;
1919

20+
/**
21+
* Resolver constructor.
22+
*
23+
* @param Strategy\Factory $factory
24+
*/
2025
public function __construct(\Magento\Framework\App\Cache\Tag\Strategy\Factory $factory)
2126
{
2227
$this->strategyFactory = $factory;
@@ -37,4 +42,4 @@ public function getTags($object)
3742

3843
return $this->strategyFactory->getStrategy($object)->getTags($object);
3944
}
40-
}
45+
}

lib/internal/Magento/Framework/App/Cache/Tag/Strategy/Factory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class Factory
3333
*/
3434
private $customStrategies = [];
3535

36+
/**
37+
* Factory constructor.
38+
*
39+
* @param Identifier $identifierStrategy
40+
* @param Dummy $dummyStrategy
41+
* @param array $customStrategies
42+
*/
3643
public function __construct(
3744
\Magento\Framework\App\Cache\Tag\Strategy\Identifier $identifierStrategy,
3845
\Magento\Framework\App\Cache\Tag\Strategy\Dummy $dummyStrategy,
@@ -73,4 +80,4 @@ class_implements($object)
7380

7481
return $this->dummyStrategy;
7582
}
76-
}
83+
}

lib/internal/Magento/Framework/App/Test/Unit/Cache/Tag/ResolverTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class ResolverTest extends \PHPUnit_Framework_TestCase
2828
protected function setUp()
2929
{
3030
$this->strategyFactory = $this->getMock(
31-
\Magento\Framework\App\Cache\Tag\Strategy\Factory::class, [], [], '', false
31+
\Magento\Framework\App\Cache\Tag\Strategy\Factory::class,
32+
[],
33+
[],
34+
'',
35+
false
3236
);
3337

3438
$this->strategy = $this->getMockForAbstractClass(\Magento\Framework\App\Cache\Tag\StrategyInterface::class);

lib/internal/Magento/Framework/App/Test/Unit/Cache/Tag/Strategy/FactoryTest.php

Lines changed: 11 additions & 3 deletions
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\Cache\Tag;
7+
namespace Magento\Framework\App\Test\Unit\Cache\Tag\Strategy;
88

99
use \Magento\Framework\App\Cache\Tag\Strategy\Factory;
1010

@@ -33,11 +33,19 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
3333
protected function setUp()
3434
{
3535
$this->identifierStrategy = $this->getMock(
36-
\Magento\Framework\App\Cache\Tag\Strategy\Identifier::class, [], [], '', false
36+
\Magento\Framework\App\Cache\Tag\Strategy\Identifier::class,
37+
[],
38+
[],
39+
'',
40+
false
3741
);
3842

3943
$this->dummyStrategy = $this->getMock(
40-
\Magento\Framework\App\Cache\Tag\Strategy\Dummy::class, [], [], '', false
44+
\Magento\Framework\App\Cache\Tag\Strategy\Dummy::class,
45+
[],
46+
[],
47+
'',
48+
false
4149
);
4250

4351
$this->customStrategy = $this->getMockForAbstractClass(

0 commit comments

Comments
 (0)