@@ -69,24 +69,29 @@ class CacheTest extends TestCase
69
69
/**
70
70
* @inheritdoc
71
71
*/
72
- public function setUp (): void
72
+ protected function setUp (): void
73
73
{
74
74
$ this ->objectManager = Bootstrap::getObjectManager ();
75
75
$ this ->graphQlRequest = $ this ->objectManager ->create (GraphQlRequest::class);
76
76
$ this ->cacheState = $ this ->objectManager ->get (CacheState::class);
77
77
$ this ->origCacheEnabled = $ this ->cacheState ->isEnabled (Type::TYPE_IDENTIFIER );
78
+
78
79
if (!$ this ->origCacheEnabled ) {
79
80
$ this ->cacheState ->setEnabled (Type::TYPE_IDENTIFIER , true );
80
81
$ this ->cacheState ->persist ();
81
82
}
83
+
82
84
$ this ->graphQlResolverCache = $ this ->objectManager ->get (Type::class);
83
85
$ this ->graphQlResolverCache ->clean ();
86
+
87
+ $ this ->preconfigureMocks ();
88
+ $ this ->configurePlugin ();
84
89
}
85
90
86
91
/**
87
92
* @inheritdoc
88
93
*/
89
- public function tearDown (): void
94
+ protected function tearDown (): void
90
95
{
91
96
$ this ->cacheState ->setEnabled (Type::TYPE_IDENTIFIER , $ this ->origCacheEnabled );
92
97
$ this ->cacheState ->persist ();
@@ -97,33 +102,36 @@ public function tearDown(): void
97
102
/**
98
103
* @magentoAppArea graphql
99
104
*/
100
- public function testCachingSkippedOnKeyCalculationFailure ()
105
+ public function testCachingSkippedOnKeyCalculationFailure (): void
101
106
{
102
- $ this ->preconfigureMocks ();
103
- $ this ->configurePlugin ();
104
107
$ this ->keyFactorMock ->expects ($ this ->any ())
105
108
->method ('getFactorValue ' )
106
109
->willThrowException (new \Exception ("Test key factor exception " ));
110
+
107
111
$ this ->graphqlResolverCacheMock ->expects ($ this ->never ())
108
112
->method ('load ' );
113
+
109
114
$ this ->graphqlResolverCacheMock ->expects ($ this ->never ())
110
115
->method ('save ' );
116
+
111
117
$ this ->graphQlRequest ->send ($ this ->getTestQuery ());
112
118
}
113
119
114
120
/**
115
121
* @magentoAppArea graphql
116
122
*/
117
- public function testCachingNotSkippedWhenKeysOk ()
123
+ public function testCachingNotSkippedWhenKeysOk (): void
118
124
{
119
- $ this ->preconfigureMocks ();
120
- $ this -> configurePlugin ( );
121
- $ this -> loggerMock -> expects ( $ this -> never ())-> method ( ' warning ' );
125
+ $ this ->loggerMock -> expects ( $ this -> never ())
126
+ -> method ( ' warning ' );
127
+
122
128
$ this ->graphqlResolverCacheMock ->expects ($ this ->once ())
123
129
->method ('load ' )
124
130
->willReturn (false );
131
+
125
132
$ this ->graphqlResolverCacheMock ->expects ($ this ->once ())
126
133
->method ('save ' );
134
+
127
135
$ this ->graphQlRequest ->send ($ this ->getTestQuery ());
128
136
}
129
137
@@ -132,25 +140,13 @@ public function testCachingNotSkippedWhenKeysOk()
132
140
*
133
141
* @return void
134
142
*/
135
- private function preconfigureMocks ()
143
+ private function preconfigureMocks (): void
136
144
{
137
- $ this ->loggerMock = $ this ->getMockBuilder (LoggerInterface::class)
138
- ->disableOriginalConstructor ()
139
- ->onlyMethods (['warning ' ])
140
- ->setMockClassName ('CacheLoggerMockForTest ' )
141
- ->getMockForAbstractClass ();
142
-
143
- $ this ->graphqlResolverCacheMock = $ this ->getMockBuilder (Type::class)
144
- ->disableOriginalConstructor ()
145
- ->onlyMethods (['load ' , 'save ' ])
146
- ->setMockClassName ('GraphqlResolverCacheMockForTest ' )
147
- ->getMock ();
148
-
149
- $ this ->keyFactorMock = $ this ->getMockBuilder (GenericFactorProviderInterface::class)
150
- ->disableOriginalConstructor ()
151
- ->onlyMethods (['getFactorValue ' , 'getFactorName ' ])
152
- ->setMockClassName ('TestFailingKeyFactor ' )
153
- ->getMock ();
145
+ $ this ->loggerMock = $ this ->createMock (LoggerInterface::class);
146
+
147
+ $ this ->graphqlResolverCacheMock = $ this ->createMock (Type::class);
148
+
149
+ $ this ->keyFactorMock = $ this ->createMock (GenericFactorProviderInterface::class);
154
150
155
151
$ this ->objectManager ->addSharedInstance ($ this ->keyFactorMock , 'TestFailingKeyFactor ' );
156
152
@@ -180,12 +176,7 @@ private function preconfigureMocks()
180
176
]
181
177
);
182
178
183
- $ identityProviderMock = $ this ->getMockBuilder (IdentityInterface::class)
184
- ->disableOriginalConstructor ()
185
- ->onlyMethods (['getIdentities ' ])
186
- ->setMockClassName ('TestIdentityProvider ' )
187
- ->getMock ();
188
-
179
+ $ identityProviderMock = $ this ->createMock (IdentityInterface::class);
189
180
$ identityProviderMock ->expects ($ this ->any ())
190
181
->method ('getIdentities ' )
191
182
->willReturn (['test_identity ' ]);
@@ -205,7 +196,7 @@ private function preconfigureMocks()
205
196
);
206
197
}
207
198
208
- private function getTestQuery ()
199
+ private function getTestQuery (): string
209
200
{
210
201
return <<<QUERY
211
202
{
@@ -224,12 +215,13 @@ private function getTestQuery()
224
215
*
225
216
* @return void
226
217
*/
227
- private function configurePlugin ()
218
+ private function configurePlugin (): void
228
219
{
229
220
// need to reset plugins list to inject new plugin with mocks as it is cached at runtime
230
221
/** @var PluginList $pluginList */
231
222
$ pluginList = $ this ->objectManager ->get (PluginList::class);
232
223
$ pluginList ->reset ();
224
+
233
225
$ this ->objectManager ->removeSharedInstance (CachePlugin::class);
234
226
$ this ->objectManager ->addSharedInstance (
235
227
$ this ->objectManager ->create (CachePlugin::class, [
0 commit comments