Skip to content

Commit a5fabfb

Browse files
committed
Updated config helper to use isSetFlag on boolean fields
1 parent c571902 commit a5fabfb

File tree

2 files changed

+53
-52
lines changed

2 files changed

+53
-52
lines changed

Helper/Config.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ public function isEnabled(): bool
105105

106106
public function isActive(): bool
107107
{
108-
return $this->scopeConfig->getValue(self::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
108+
return $this->scopeConfig->isSetFlag(self::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
109109
}
110110

111111
public function isAdminhtmlActive(): bool
112112
{
113-
return $this->scopeConfig->getValue(self::CONFIG_ENABLED_ADMINHTML, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
113+
return $this->scopeConfig->isSetFlag(self::CONFIG_ENABLED_ADMINHTML, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
114114
}
115115

116116
/**
@@ -175,95 +175,95 @@ public function getCollectorClass(string $name): string
175175

176176
public function isAjaxCollectorEnabled(): bool
177177
{
178-
return (bool) $this->scopeConfig->getValue(
178+
return $this->scopeConfig->isSetFlag(
179179
self::CONFIG_COLLECTOR_AJAX,
180180
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
181181
);
182182
}
183183

184184
public function isCacheCollectorEnabled(): bool
185185
{
186-
return (bool) $this->scopeConfig->getValue(
186+
return $this->scopeConfig->isSetFlag(
187187
self::CONFIG_COLLECTOR_CACHE,
188188
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
189189
);
190190
}
191191

192192
public function isConfigCollectorEnabled(): bool
193193
{
194-
return (bool) $this->scopeConfig->getValue(
194+
return $this->scopeConfig->isSetFlag(
195195
self::CONFIG_COLLECTOR_CONFIG,
196196
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
197197
);
198198
}
199199

200200
public function isCustomerCollectorEnabled(): bool
201201
{
202-
return (bool) $this->scopeConfig->getValue(
202+
return $this->scopeConfig->isSetFlag(
203203
self::CONFIG_COLLECTOR_CUSTOMER,
204204
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
205205
);
206206
}
207207

208208
public function isDatabaseCollectorEnabled(): bool
209209
{
210-
return $this->scopeConfig->getValue(
210+
return $this->scopeConfig->isSetFlag(
211211
self::CONFIG_COLLECTOR_DATABASE,
212212
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
213213
) && $this->deploymentConfig->get('db/connection/default/profiler/enabled');
214214
}
215215

216216
public function isEventCollectorEnabled(): bool
217217
{
218-
return (bool) $this->scopeConfig->getValue(
218+
return $this->scopeConfig->isSetFlag(
219219
self::CONFIG_COLLECTOR_EVENT,
220220
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
221221
);
222222
}
223223

224224
public function isPluginCollectorEnabled(): bool
225225
{
226-
return (bool) $this->scopeConfig->getValue(
226+
return $this->scopeConfig->isSetFlag(
227227
self::CONFIG_COLLECTOR_PLUGIN,
228228
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
229229
);
230230
}
231231

232232
public function isLayoutCollectorEnabled(): bool
233233
{
234-
return $this->scopeConfig->getValue(
234+
return $this->scopeConfig->isSetFlag(
235235
self::CONFIG_COLLECTOR_LAYOUT,
236236
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
237237
) && !$this->httpStorage->isFPCRequest();
238238
}
239239

240240
public function isMemoryCollectorEnabled(): bool
241241
{
242-
return (bool) $this->scopeConfig->getValue(
242+
return $this->scopeConfig->isSetFlag(
243243
self::CONFIG_COLLECTOR_MEMORY,
244244
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
245245
);
246246
}
247247

248248
public function isModelCollectorEnabled(): bool
249249
{
250-
return (bool) $this->scopeConfig->getValue(
250+
return $this->scopeConfig->isSetFlag(
251251
self::CONFIG_COLLECTOR_MODEL,
252252
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
253253
);
254254
}
255255

256256
public function isTimeCollectorEnabled(): bool
257257
{
258-
return (bool) $this->scopeConfig->getValue(
258+
return $this->scopeConfig->isSetFlag(
259259
self::CONFIG_COLLECTOR_TIME,
260260
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
261261
);
262262
}
263263

264264
public function isTranslationCollectorEnabled(): bool
265265
{
266-
return $this->scopeConfig->getValue(
266+
return $this->scopeConfig->isSetFlag(
267267
self::CONFIG_COLLECTOR_TRANSLATION,
268268
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
269269
) && !$this->httpStorage->isFPCRequest();

Test/Unit/Helper/ConfigTest.php

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ public function testGetErrorHandler()
7777

7878
$this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn(Area::AREA_FRONTEND);
7979

80-
$this->scopeConfigMock->expects($this->exactly(2))->method('getValue')
81-
->withConsecutive(
82-
[Config::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
83-
[Config::CONFIG_ERROR_HANDLER, ScopeConfigInterface::SCOPE_TYPE_DEFAULT]
84-
)
85-
->willReturnOnConsecutiveCalls(true, ErrorHandler::WHOOPS);
80+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
81+
->with(Config::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
82+
->willReturn(true);
83+
84+
$this->scopeConfigMock->expects($this->once())->method('getValue')
85+
->with(Config::CONFIG_ERROR_HANDLER, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
86+
->willReturn(ErrorHandler::WHOOPS);
8687

8788
$this->assertEquals(ErrorHandler::WHOOPS, $this->config->getErrorHandler());
8889
}
@@ -95,9 +96,9 @@ public function testGetErrorHandlerDefault()
9596

9697
public function testIsDatabaseCollectorEnabled()
9798
{
98-
$this->scopeConfigMock->expects($this->once())->method('getValue')
99+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
99100
->with(Config::CONFIG_COLLECTOR_DATABASE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
100-
->willReturn('1');
101+
->willReturn(true);
101102

102103
$this->deploymentConfigMock->expects($this->once())->method('get')
103104
->with('db/connection/default/profiler/enabled')
@@ -108,49 +109,49 @@ public function testIsDatabaseCollectorEnabled()
108109

109110
public function testIsAjaxCollectorEnabled()
110111
{
111-
$this->scopeConfigMock->expects($this->once())->method('getValue')
112+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
112113
->with(Config::CONFIG_COLLECTOR_AJAX, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
113-
->willReturn('1');
114+
->willReturn(true);
114115
$this->assertTrue($this->config->isAjaxCollectorEnabled());
115116
}
116117

117118
public function testIsAdminhtmlActive()
118119
{
119-
$this->scopeConfigMock->expects($this->once())->method('getValue')
120+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
120121
->with(Config::CONFIG_ENABLED_ADMINHTML, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
121-
->willReturn('1');
122+
->willReturn(true);
122123
$this->assertTrue($this->config->isAdminhtmlActive());
123124
}
124125

125126
public function testIsConfigCollectorEnabled()
126127
{
127-
$this->scopeConfigMock->expects($this->once())->method('getValue')
128+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
128129
->with(Config::CONFIG_COLLECTOR_CONFIG, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
129-
->willReturn('1');
130+
->willReturn(true);
130131
$this->assertTrue($this->config->isConfigCollectorEnabled());
131132
}
132133

133134
public function testIsModelCollectorEnabled()
134135
{
135-
$this->scopeConfigMock->expects($this->once())->method('getValue')
136+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
136137
->with(Config::CONFIG_COLLECTOR_MODEL, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
137-
->willReturn('1');
138+
->willReturn(true);
138139
$this->assertTrue($this->config->isModelCollectorEnabled());
139140
}
140141

141142
public function testIsPluginCollectorEnabled()
142143
{
143-
$this->scopeConfigMock->expects($this->once())->method('getValue')
144+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
144145
->with(Config::CONFIG_COLLECTOR_PLUGIN, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
145-
->willReturn('1');
146+
->willReturn(true);
146147
$this->assertTrue($this->config->isPluginCollectorEnabled());
147148
}
148149

149150
public function testIsTranslationCollectorEnabled()
150151
{
151-
$this->scopeConfigMock->expects($this->once())->method('getValue')
152+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
152153
->with(Config::CONFIG_COLLECTOR_TRANSLATION, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
153-
->willReturn('1');
154+
->willReturn(true);
154155
$this->assertTrue($this->config->isTranslationCollectorEnabled());
155156
}
156157

@@ -164,44 +165,44 @@ public function testGetCollectors()
164165

165166
public function testIsLayoutCollectorEnabled()
166167
{
167-
$this->scopeConfigMock->expects($this->once())->method('getValue')
168+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
168169
->with(Config::CONFIG_COLLECTOR_LAYOUT, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
169-
->willReturn('1');
170+
->willReturn(true);
170171
$this->assertTrue($this->config->isLayoutCollectorEnabled());
171172
}
172173

173174
public function testIsMemoryCollectorEnabled()
174175
{
175-
$this->scopeConfigMock->expects($this->once())->method('getValue')
176+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
176177
->with(Config::CONFIG_COLLECTOR_MEMORY, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
177-
->willReturn('1');
178+
->willReturn(true);
178179
$this->assertTrue($this->config->isMemoryCollectorEnabled());
179180
}
180181

181182
public function testIsCustomerCollectorEnabled()
182183
{
183-
$this->scopeConfigMock->expects($this->once())->method('getValue')
184+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
184185
->with(Config::CONFIG_COLLECTOR_CUSTOMER, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
185-
->willReturn('1');
186+
->willReturn(true);
186187
$this->assertTrue($this->config->isCustomerCollectorEnabled());
187188
}
188189

189190
public function testIsEnabledNotActive()
190191
{
191192
$this->appStateMock->expects($this->once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
192-
$this->scopeConfigMock->expects($this->once())->method('getValue')
193+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
193194
->with(Config::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
194-
->willReturn('0');
195+
->willReturn(false);
195196
$this->assertFalse($this->config->isEnabled());
196197
}
197198

198199
public function testIsDisabledForAdminhtml()
199200
{
200-
$this->scopeConfigMock->expects($this->exactly(2))->method('getValue')
201+
$this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')
201202
->withConsecutive(
202203
[Config::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
203204
[Config::CONFIG_ENABLED_ADMINHTML, ScopeConfigInterface::SCOPE_TYPE_DEFAULT]
204-
)->willReturnOnConsecutiveCalls('1', '0');
205+
)->willReturnOnConsecutiveCalls(true, false);
205206
$this->appStateMock->expects($this->once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
206207
$this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn(Area::AREA_ADMINHTML);
207208
$this->assertFalse($this->config->isEnabled());
@@ -218,9 +219,9 @@ public function testIsAllowedIP()
218219

219220
public function testIsTimeCollectorEnabled()
220221
{
221-
$this->scopeConfigMock->expects($this->once())->method('getValue')
222+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
222223
->with(Config::CONFIG_COLLECTOR_TIME, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
223-
->willReturn('1');
224+
->willReturn(true);
224225
$this->assertTrue($this->config->isTimeCollectorEnabled());
225226
}
226227

@@ -269,25 +270,25 @@ public function testGetCollectorClassNotFound()
269270

270271
public function testIsCacheCollectorEnabled()
271272
{
272-
$this->scopeConfigMock->expects($this->once())->method('getValue')
273+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
273274
->with(Config::CONFIG_COLLECTOR_CACHE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
274-
->willReturn('1');
275+
->willReturn(true);
275276
$this->assertTrue($this->config->isCacheCollectorEnabled());
276277
}
277278

278279
public function testIsEventCollectorEnabled()
279280
{
280-
$this->scopeConfigMock->expects($this->once())->method('getValue')
281+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
281282
->with(Config::CONFIG_COLLECTOR_EVENT, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
282-
->willReturn('1');
283+
->willReturn(true);
283284
$this->assertTrue($this->config->isEventCollectorEnabled());
284285
}
285286

286287
public function testIsActive()
287288
{
288-
$this->scopeConfigMock->expects($this->once())->method('getValue')
289+
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')
289290
->with(Config::CONFIG_ENABLED, ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
290-
->willReturn('0');
291+
->willReturn(false);
291292
$this->assertFalse($this->config->isActive());
292293
}
293294

0 commit comments

Comments
 (0)