Skip to content

Commit 1e317e4

Browse files
committed
ACP2E-3063: [Cloud] Cache is not getting invalidated.
- with test
1 parent 87ec4ac commit 1e317e4

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

app/code/Magento/Theme/Test/Unit/Observer/InvalidateLayoutCacheObserverTest.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
namespace Magento\Theme\Test\Unit\Observer;
2020

21-
use Magento\Theme\Model\LayoutCacheTagResolverFactory;
21+
use Magento\Framework\App\Cache\Tag\Strategy\Factory;
22+
use Magento\Framework\App\Cache\Tag\StrategyInterface;
2223
use Magento\Theme\Observer\InvalidateLayoutCacheObserver;
2324
use Magento\Framework\App\Cache\StateInterface as CacheState;
2425
use Magento\Framework\App\Cache\Type\Layout as LayoutCache;
@@ -27,7 +28,6 @@
2728
use Magento\Framework\Event\Observer;
2829
use PHPUnit\Framework\MockObject\MockObject;
2930
use PHPUnit\Framework\TestCase;
30-
use Random\RandomException;
3131

3232
class InvalidateLayoutCacheObserverTest extends TestCase
3333
{
@@ -47,9 +47,9 @@ class InvalidateLayoutCacheObserverTest extends TestCase
4747
private $cacheStateMock;
4848

4949
/**
50-
* @var LayoutCacheTagResolverFactory|MockObject
50+
* @var Factory|MockObject
5151
*/
52-
private $tagResolverMock;
52+
private $strategyFactory;
5353

5454
/**
5555
* @var Observer|MockObject
@@ -76,13 +76,12 @@ protected function setUp(): void
7676
->getMockBuilder(LayoutCache::class)
7777
->onlyMethods(['clean'])
7878
->disableOriginalConstructor()
79-
->getMockForAbstractClass();
80-
$this->tagResolverMock = $this
81-
->getMockBuilder(LayoutCacheTagResolverFactory::class)
82-
->addMethods(['getTags'])
83-
->onlyMethods(['getResolver'])
79+
->getMock();
80+
$this->strategyFactory = $this
81+
->getMockBuilder(Factory::class)
82+
->onlyMethods(['getStrategy'])
8483
->disableOriginalConstructor()
85-
->getMockForAbstractClass();
84+
->getMock();
8685
$this->observerMock = $this
8786
->getMockBuilder(Observer::class)
8887
->disableOriginalConstructor()
@@ -106,7 +105,7 @@ protected function setUp(): void
106105
$this->invalidateLayoutCacheObserver = new InvalidateLayoutCacheObserver(
107106
$this->layoutCacheMock,
108107
$this->cacheStateMock,
109-
$this->tagResolverMock
108+
$this->strategyFactory
110109
);
111110
}
112111

@@ -116,7 +115,6 @@ protected function setUp(): void
116115
* @param bool $cacheIsEnabled
117116
* @param bool $isDataChangedFor
118117
* @param bool $isObjectNew
119-
* @param object|null $cacheStrategy
120118
* @param array $tags
121119
* @throws RandomException
122120
* @dataProvider invalidateLayoutCacheDataProvider
@@ -125,9 +123,13 @@ public function testExecute(
125123
bool $cacheIsEnabled,
126124
bool $isDataChangedFor,
127125
bool $isObjectNew,
128-
?object $cacheStrategy,
129126
array $tags
130127
): void {
128+
$cacheStrategy = $this
129+
->getMockBuilder(StrategyInterface::class)
130+
->onlyMethods(['getTags'])
131+
->disableOriginalConstructor()
132+
->getMock();
131133
$this->observerMock
132134
->expects($this->atLeastOnce())
133135
->method('getEvent')
@@ -152,11 +154,11 @@ public function testExecute(
152154
->expects($this->any())
153155
->method('getIdentifier')
154156
->willReturn(random_int(1, 100));
155-
$this->tagResolverMock
157+
$this->strategyFactory
156158
->expects($this->any())
157-
->method('getResolver')
159+
->method('getStrategy')
158160
->willReturn($cacheStrategy);
159-
$this->tagResolverMock
161+
$cacheStrategy
160162
->expects($this->any())
161163
->method('getTags')
162164
->with($this->objectMock)
@@ -176,11 +178,11 @@ public function testExecute(
176178
public static function invalidateLayoutCacheDataProvider(): array
177179
{
178180
return [
179-
'when layout cache is not enabled' => [false, true, false, null, []],
180-
'when cache is not changed' => [true, false, false, null, []],
181-
'when object is new' => [true, true, false, null, []],
182-
'when tag is empty' => [true, true, false, null, []],
183-
'when tag is not empty' => [true, true, false, null, ['cms_p']],
181+
'when layout cache is not enabled' => [false, true, false, []],
182+
'when cache is not changed' => [true, false, false, []],
183+
'when object is new' => [true, true, false, []],
184+
'when tag is empty' => [true, true, false, []],
185+
'when tag is not empty' => [true, true, false, ['cms_p']],
184186
];
185187
}
186188
}

0 commit comments

Comments
 (0)