Skip to content

Commit ae99e32

Browse files
committed
test: Reduce PHPUnit notices - Mocks have assertions or need to turn to stubs
1 parent b5fc915 commit ae99e32

13 files changed

Lines changed: 623 additions & 368 deletions

test/Assets/ResponsiveAssetsTest.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
#[CoversClass(ResponsiveAssets::class)]
2626
class ResponsiveAssetsTest extends TestCase
2727
{
28-
private $registryMock;
29-
private $filesystemMock;
28+
private $registryStub;
29+
private $filesystemStub;
3030

3131
protected function setUp(): void
3232
{
33-
$this->registryMock = $this->createMock(Horde_Registry::class);
34-
$this->filesystemMock = $this->createMock(ResponsiveAssetsFilesystem::class);
33+
$this->registryStub = $this->createStub(Horde_Registry::class);
34+
$this->filesystemStub = $this->createStub(ResponsiveAssetsFilesystem::class);
3535
}
3636

3737
public function testGetCssUrlsHordeOnly(): void
3838
{
39-
// Setup registry mock
40-
$this->registryMock->method('get')
39+
// Setup registry stub
40+
$this->registryStub->method('get')
4141
->willReturnCallback(function ($key, $app) {
4242
if ($key === 'themesfs' && $app === 'horde') {
4343
return '/horde/themes';
@@ -48,17 +48,17 @@ public function testGetCssUrlsHordeOnly(): void
4848
return null;
4949
});
5050

51-
$this->registryMock->method('getApp')
51+
$this->registryStub->method('getApp')
5252
->willReturn('horde');
5353

54-
// Setup filesystem mock - file exists
55-
$this->filesystemMock->method('fileExists')
54+
// Setup filesystem stub - file exists
55+
$this->filesystemStub->method('fileExists')
5656
->willReturnCallback(function ($path) {
5757
return $path === '/horde/themes/default/responsive.css';
5858
});
5959

6060
// Create assets helper
61-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
61+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
6262

6363
// Get CSS URLs
6464
$urls = $assets->getCssUrls('default', 'horde');
@@ -72,7 +72,7 @@ public function testGetCssUrlsHordeOnly(): void
7272
public function testGetCssUrlsWithAppCascade(): void
7373
{
7474
// Setup: Both horde and kronolith have responsive.css
75-
$this->registryMock->method('get')
75+
$this->registryStub->method('get')
7676
->willReturnCallback(function ($key, $app) {
7777
if ($key === 'themesfs') {
7878
return $app === 'horde' ? '/horde/themes' : '/kronolith/themes';
@@ -83,16 +83,16 @@ public function testGetCssUrlsWithAppCascade(): void
8383
return null;
8484
});
8585

86-
$this->registryMock->method('getApp')
86+
$this->registryStub->method('getApp')
8787
->willReturn('kronolith');
8888

8989
// Both files exist
90-
$this->filesystemMock->method('fileExists')
90+
$this->filesystemStub->method('fileExists')
9191
->willReturnCallback(function ($path) {
9292
return str_contains($path, 'responsive.css');
9393
});
9494

95-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
95+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
9696
$urls = $assets->getCssUrls('default', 'kronolith');
9797

9898
// Verify cascade order: horde first, app second
@@ -104,16 +104,16 @@ public function testGetCssUrlsWithAppCascade(): void
104104
public function testGetCssUrlsFileNotFound(): void
105105
{
106106
// Setup: File doesn't exist
107-
$this->filesystemMock->method('fileExists')
107+
$this->filesystemStub->method('fileExists')
108108
->willReturn(false);
109109

110-
$this->registryMock->method('get')
110+
$this->registryStub->method('get')
111111
->willReturn('/horde/themes');
112112

113-
$this->registryMock->method('getApp')
113+
$this->registryStub->method('getApp')
114114
->willReturn('horde');
115115

116-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
116+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
117117
$urls = $assets->getCssUrls('default', 'horde');
118118

119119
// No URLs returned when files don't exist
@@ -123,7 +123,7 @@ public function testGetCssUrlsFileNotFound(): void
123123
public function testGetCssUrlsOnlyAppFileExists(): void
124124
{
125125
// Setup: Only app file exists, not horde base
126-
$this->registryMock->method('get')
126+
$this->registryStub->method('get')
127127
->willReturnCallback(function ($key, $app) {
128128
if ($key === 'themesfs') {
129129
return $app === 'horde' ? '/horde/themes' : '/kronolith/themes';
@@ -134,16 +134,16 @@ public function testGetCssUrlsOnlyAppFileExists(): void
134134
return null;
135135
});
136136

137-
$this->registryMock->method('getApp')
137+
$this->registryStub->method('getApp')
138138
->willReturn('kronolith');
139139

140140
// Only kronolith file exists
141-
$this->filesystemMock->method('fileExists')
141+
$this->filesystemStub->method('fileExists')
142142
->willReturnCallback(function ($path) {
143143
return str_contains($path, '/kronolith/');
144144
});
145145

146-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
146+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
147147
$urls = $assets->getCssUrls('default', 'kronolith');
148148

149149
// Only app URL returned
@@ -154,7 +154,7 @@ public function testGetCssUrlsOnlyAppFileExists(): void
154154
public function testGetJsUrlsHordeOnly(): void
155155
{
156156
// Setup registry mock
157-
$this->registryMock->method('get')
157+
$this->registryStub->method('get')
158158
->willReturnCallback(function ($key, $app) {
159159
if ($key === 'jsfs' && $app === 'horde') {
160160
return '/horde/js';
@@ -165,16 +165,16 @@ public function testGetJsUrlsHordeOnly(): void
165165
return null;
166166
});
167167

168-
$this->registryMock->method('getApp')
168+
$this->registryStub->method('getApp')
169169
->willReturn('horde');
170170

171171
// File exists
172-
$this->filesystemMock->method('fileExists')
172+
$this->filesystemStub->method('fileExists')
173173
->willReturnCallback(function ($path) {
174174
return $path === '/horde/js/login-form.js';
175175
});
176176

177-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
177+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
178178
$urls = $assets->getJsUrls(['login-form.js'], 'horde');
179179

180180
// Verify
@@ -186,7 +186,7 @@ public function testGetJsUrlsHordeOnly(): void
186186
public function testGetJsUrlsWithAppCascade(): void
187187
{
188188
// Setup: Both horde and kronolith have calendar.js
189-
$this->registryMock->method('get')
189+
$this->registryStub->method('get')
190190
->willReturnCallback(function ($key, $app) {
191191
if ($key === 'jsfs') {
192192
return $app === 'horde' ? '/horde/js' : '/kronolith/js';
@@ -197,14 +197,14 @@ public function testGetJsUrlsWithAppCascade(): void
197197
return null;
198198
});
199199

200-
$this->registryMock->method('getApp')
200+
$this->registryStub->method('getApp')
201201
->willReturn('kronolith');
202202

203203
// Both files exist
204-
$this->filesystemMock->method('fileExists')
204+
$this->filesystemStub->method('fileExists')
205205
->willReturn(true);
206206

207-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
207+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
208208
$urls = $assets->getJsUrls(['calendar.js'], 'kronolith');
209209

210210
// Verify cascade: horde first, app second
@@ -216,7 +216,7 @@ public function testGetJsUrlsWithAppCascade(): void
216216
public function testGetJsUrlsMultipleFiles(): void
217217
{
218218
// Setup
219-
$this->registryMock->method('get')
219+
$this->registryStub->method('get')
220220
->willReturnCallback(function ($key, $app) {
221221
if ($key === 'jsfs') {
222222
return '/horde/js';
@@ -227,14 +227,14 @@ public function testGetJsUrlsMultipleFiles(): void
227227
return null;
228228
});
229229

230-
$this->registryMock->method('getApp')
230+
$this->registryStub->method('getApp')
231231
->willReturn('horde');
232232

233233
// All files exist
234-
$this->filesystemMock->method('fileExists')
234+
$this->filesystemStub->method('fileExists')
235235
->willReturn(true);
236236

237-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
237+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
238238
$urls = $assets->getJsUrls(['file1.js', 'file2.js', 'file3.js'], 'horde');
239239

240240
// All URLs returned
@@ -246,10 +246,10 @@ public function testGetJsUrlsMultipleFiles(): void
246246

247247
public function testGetJsUrlsEmptyArray(): void
248248
{
249-
$this->registryMock->method('getApp')
249+
$this->registryStub->method('getApp')
250250
->willReturn('horde');
251251

252-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
252+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
253253
$urls = $assets->getJsUrls([], 'horde');
254254

255255
// No JS files requested, empty array returned
@@ -261,24 +261,24 @@ public function testGetTheme(): void
261261
// No preferences set, should return 'default'
262262
$GLOBALS['prefs'] = null;
263263

264-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
264+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
265265
$theme = $assets->getTheme();
266266

267267
$this->assertEquals('default', $theme);
268268
}
269269

270270
public function testGetThemeWithPreference(): void
271271
{
272-
// Mock preferences
273-
$prefsMock = $this->createMock(\Horde_Prefs::class);
274-
$prefsMock->method('getValue')
272+
// Stub preferences
273+
$prefsStub = $this->createStub(\Horde_Prefs::class);
274+
$prefsStub->method('getValue')
275275
->willReturnCallback(function ($key) {
276276
return $key === 'theme' ? 'dark' : null;
277277
});
278278

279-
$GLOBALS['prefs'] = $prefsMock;
279+
$GLOBALS['prefs'] = $prefsStub;
280280

281-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
281+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
282282
$theme = $assets->getTheme();
283283

284284
$this->assertEquals('dark', $theme);
@@ -290,13 +290,13 @@ public function testGetThemeWithPreference(): void
290290
public function testCssFileExistsHandlesException(): void
291291
{
292292
// Registry throws exception
293-
$this->registryMock->method('get')
293+
$this->registryStub->method('get')
294294
->willThrowException(new \Exception('Registry error'));
295295

296-
$this->registryMock->method('getApp')
296+
$this->registryStub->method('getApp')
297297
->willReturn('horde');
298298

299-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
299+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
300300
$urls = $assets->getCssUrls('default', 'horde');
301301

302302
// Should gracefully handle exception and return empty array
@@ -306,13 +306,13 @@ public function testCssFileExistsHandlesException(): void
306306
public function testJsFileExistsHandlesException(): void
307307
{
308308
// Registry throws exception
309-
$this->registryMock->method('get')
309+
$this->registryStub->method('get')
310310
->willThrowException(new \Exception('Registry error'));
311311

312-
$this->registryMock->method('getApp')
312+
$this->registryStub->method('getApp')
313313
->willReturn('horde');
314314

315-
$assets = new ResponsiveAssets($this->registryMock, $this->filesystemMock);
315+
$assets = new ResponsiveAssets($this->registryStub, $this->filesystemStub);
316316
$urls = $assets->getJsUrls(['test.js'], 'horde');
317317

318318
// Should gracefully handle exception and return empty array

0 commit comments

Comments
 (0)