18
18
19
19
namespace Magento \Theme \Test \Unit \Observer ;
20
20
21
- use Magento \Theme \Model \LayoutCacheTagResolverFactory ;
21
+ use Magento \Framework \App \Cache \Tag \Strategy \Factory ;
22
+ use Magento \Framework \App \Cache \Tag \StrategyInterface ;
22
23
use Magento \Theme \Observer \InvalidateLayoutCacheObserver ;
23
24
use Magento \Framework \App \Cache \StateInterface as CacheState ;
24
25
use Magento \Framework \App \Cache \Type \Layout as LayoutCache ;
27
28
use Magento \Framework \Event \Observer ;
28
29
use PHPUnit \Framework \MockObject \MockObject ;
29
30
use PHPUnit \Framework \TestCase ;
30
- use Random \RandomException ;
31
31
32
32
class InvalidateLayoutCacheObserverTest extends TestCase
33
33
{
@@ -47,9 +47,9 @@ class InvalidateLayoutCacheObserverTest extends TestCase
47
47
private $ cacheStateMock ;
48
48
49
49
/**
50
- * @var LayoutCacheTagResolverFactory |MockObject
50
+ * @var Factory |MockObject
51
51
*/
52
- private $ tagResolverMock ;
52
+ private $ strategyFactory ;
53
53
54
54
/**
55
55
* @var Observer|MockObject
@@ -76,13 +76,12 @@ protected function setUp(): void
76
76
->getMockBuilder (LayoutCache::class)
77
77
->onlyMethods (['clean ' ])
78
78
->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 ' ])
84
83
->disableOriginalConstructor ()
85
- ->getMockForAbstractClass ();
84
+ ->getMock ();
86
85
$ this ->observerMock = $ this
87
86
->getMockBuilder (Observer::class)
88
87
->disableOriginalConstructor ()
@@ -106,7 +105,7 @@ protected function setUp(): void
106
105
$ this ->invalidateLayoutCacheObserver = new InvalidateLayoutCacheObserver (
107
106
$ this ->layoutCacheMock ,
108
107
$ this ->cacheStateMock ,
109
- $ this ->tagResolverMock
108
+ $ this ->strategyFactory
110
109
);
111
110
}
112
111
@@ -116,7 +115,6 @@ protected function setUp(): void
116
115
* @param bool $cacheIsEnabled
117
116
* @param bool $isDataChangedFor
118
117
* @param bool $isObjectNew
119
- * @param object|null $cacheStrategy
120
118
* @param array $tags
121
119
* @throws RandomException
122
120
* @dataProvider invalidateLayoutCacheDataProvider
@@ -125,9 +123,13 @@ public function testExecute(
125
123
bool $ cacheIsEnabled ,
126
124
bool $ isDataChangedFor ,
127
125
bool $ isObjectNew ,
128
- ?object $ cacheStrategy ,
129
126
array $ tags
130
127
): void {
128
+ $ cacheStrategy = $ this
129
+ ->getMockBuilder (StrategyInterface::class)
130
+ ->onlyMethods (['getTags ' ])
131
+ ->disableOriginalConstructor ()
132
+ ->getMock ();
131
133
$ this ->observerMock
132
134
->expects ($ this ->atLeastOnce ())
133
135
->method ('getEvent ' )
@@ -152,11 +154,11 @@ public function testExecute(
152
154
->expects ($ this ->any ())
153
155
->method ('getIdentifier ' )
154
156
->willReturn (random_int (1 , 100 ));
155
- $ this ->tagResolverMock
157
+ $ this ->strategyFactory
156
158
->expects ($ this ->any ())
157
- ->method ('getResolver ' )
159
+ ->method ('getStrategy ' )
158
160
->willReturn ($ cacheStrategy );
159
- $ this -> tagResolverMock
161
+ $ cacheStrategy
160
162
->expects ($ this ->any ())
161
163
->method ('getTags ' )
162
164
->with ($ this ->objectMock )
@@ -176,11 +178,11 @@ public function testExecute(
176
178
public static function invalidateLayoutCacheDataProvider (): array
177
179
{
178
180
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 ' ]],
184
186
];
185
187
}
186
188
}
0 commit comments