Completed
Push — master ( c214ec...1447f1 )
by Joas
21:41
created
tests/lib/App/DependencyAnalyzerTest.php 1 patch
Indentation   +714 added lines, -714 removed lines patch added patch discarded remove patch
@@ -15,744 +15,744 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class DependencyAnalyzerTest extends TestCase {
18
-	private Platform&MockObject $platformMock;
18
+    private Platform&MockObject $platformMock;
19 19
 
20
-	private DependencyAnalyzer $analyser;
20
+    private DependencyAnalyzer $analyser;
21 21
 
22
-	protected function setUp(): void {
23
-		$this->platformMock = $this->getMockBuilder(Platform::class)
24
-			->disableOriginalConstructor()
25
-			->getMock();
26
-		$this->platformMock->expects($this->any())
27
-			->method('getPhpVersion')
28
-			->willReturn('5.4.3');
29
-		$this->platformMock->expects($this->any())
30
-			->method('getIntSize')
31
-			->willReturn(4);
32
-		$this->platformMock->expects($this->any())
33
-			->method('getDatabase')
34
-			->willReturn('mysql');
35
-		$this->platformMock->expects($this->any())
36
-			->method('getOS')
37
-			->willReturn('Linux');
38
-		$this->platformMock->expects($this->any())
39
-			->method('isCommandKnown')
40
-			->willReturnCallback(function ($command) {
41
-				return ($command === 'grep');
42
-			});
43
-		$this->platformMock->expects($this->any())
44
-			->method('getLibraryVersion')
45
-			->willReturnCallback(function ($lib) {
46
-				if ($lib === 'curl') {
47
-					return '2.3.4';
48
-				}
49
-				return null;
50
-			});
51
-		$this->platformMock->expects($this->any())
52
-			->method('getOcVersion')
53
-			->willReturn('8.0.2');
22
+    protected function setUp(): void {
23
+        $this->platformMock = $this->getMockBuilder(Platform::class)
24
+            ->disableOriginalConstructor()
25
+            ->getMock();
26
+        $this->platformMock->expects($this->any())
27
+            ->method('getPhpVersion')
28
+            ->willReturn('5.4.3');
29
+        $this->platformMock->expects($this->any())
30
+            ->method('getIntSize')
31
+            ->willReturn(4);
32
+        $this->platformMock->expects($this->any())
33
+            ->method('getDatabase')
34
+            ->willReturn('mysql');
35
+        $this->platformMock->expects($this->any())
36
+            ->method('getOS')
37
+            ->willReturn('Linux');
38
+        $this->platformMock->expects($this->any())
39
+            ->method('isCommandKnown')
40
+            ->willReturnCallback(function ($command) {
41
+                return ($command === 'grep');
42
+            });
43
+        $this->platformMock->expects($this->any())
44
+            ->method('getLibraryVersion')
45
+            ->willReturnCallback(function ($lib) {
46
+                if ($lib === 'curl') {
47
+                    return '2.3.4';
48
+                }
49
+                return null;
50
+            });
51
+        $this->platformMock->expects($this->any())
52
+            ->method('getOcVersion')
53
+            ->willReturn('8.0.2');
54 54
 
55
-		$this->analyser = new DependencyAnalyzer($this->platformMock);
56
-	}
55
+        $this->analyser = new DependencyAnalyzer($this->platformMock);
56
+    }
57 57
 
58
-	/**
59
-	 *
60
-	 * @param string $expectedMissing
61
-	 * @param string $minVersion
62
-	 * @param string $maxVersion
63
-	 * @param string $intSize
64
-	 */
65
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesPhpVersion')]
66
-	public function testPhpVersion($expectedMissing, $minVersion, $maxVersion, $intSize): void {
67
-		$app = [
68
-			'dependencies' => [
69
-				'php' => []
70
-			]
71
-		];
72
-		if (!is_null($minVersion)) {
73
-			$app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
74
-		}
75
-		if (!is_null($maxVersion)) {
76
-			$app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
77
-		}
78
-		if (!is_null($intSize)) {
79
-			$app['dependencies']['php']['@attributes']['min-int-size'] = $intSize;
80
-		}
81
-		$missing = $this->analyser->analyze($app);
58
+    /**
59
+     *
60
+     * @param string $expectedMissing
61
+     * @param string $minVersion
62
+     * @param string $maxVersion
63
+     * @param string $intSize
64
+     */
65
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesPhpVersion')]
66
+    public function testPhpVersion($expectedMissing, $minVersion, $maxVersion, $intSize): void {
67
+        $app = [
68
+            'dependencies' => [
69
+                'php' => []
70
+            ]
71
+        ];
72
+        if (!is_null($minVersion)) {
73
+            $app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
74
+        }
75
+        if (!is_null($maxVersion)) {
76
+            $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
77
+        }
78
+        if (!is_null($intSize)) {
79
+            $app['dependencies']['php']['@attributes']['min-int-size'] = $intSize;
80
+        }
81
+        $missing = $this->analyser->analyze($app);
82 82
 
83
-		$this->assertTrue(is_array($missing));
84
-		$this->assertEquals($expectedMissing, $missing);
85
-	}
83
+        $this->assertTrue(is_array($missing));
84
+        $this->assertEquals($expectedMissing, $missing);
85
+    }
86 86
 
87
-	/**
88
-	 * @param $expectedMissing
89
-	 * @param $databases
90
-	 */
91
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesDatabases')]
92
-	public function testDatabases($expectedMissing, $databases): void {
93
-		$app = [
94
-			'dependencies' => [
95
-			]
96
-		];
97
-		if (!is_null($databases)) {
98
-			$app['dependencies']['database'] = $databases;
99
-		}
100
-		$missing = $this->analyser->analyze($app);
87
+    /**
88
+     * @param $expectedMissing
89
+     * @param $databases
90
+     */
91
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesDatabases')]
92
+    public function testDatabases($expectedMissing, $databases): void {
93
+        $app = [
94
+            'dependencies' => [
95
+            ]
96
+        ];
97
+        if (!is_null($databases)) {
98
+            $app['dependencies']['database'] = $databases;
99
+        }
100
+        $missing = $this->analyser->analyze($app);
101 101
 
102
-		$this->assertTrue(is_array($missing));
103
-		$this->assertEquals($expectedMissing, $missing);
104
-	}
102
+        $this->assertTrue(is_array($missing));
103
+        $this->assertEquals($expectedMissing, $missing);
104
+    }
105 105
 
106
-	/**
107
-	 *
108
-	 * @param string $expectedMissing
109
-	 * @param string|null $commands
110
-	 */
111
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesCommands')]
112
-	public function testCommand($expectedMissing, $commands): void {
113
-		$app = [
114
-			'dependencies' => [
115
-			]
116
-		];
117
-		if (!is_null($commands)) {
118
-			$app['dependencies']['command'] = $commands;
119
-		}
120
-		$missing = $this->analyser->analyze($app);
106
+    /**
107
+     *
108
+     * @param string $expectedMissing
109
+     * @param string|null $commands
110
+     */
111
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesCommands')]
112
+    public function testCommand($expectedMissing, $commands): void {
113
+        $app = [
114
+            'dependencies' => [
115
+            ]
116
+        ];
117
+        if (!is_null($commands)) {
118
+            $app['dependencies']['command'] = $commands;
119
+        }
120
+        $missing = $this->analyser->analyze($app);
121 121
 
122
-		$this->assertTrue(is_array($missing));
123
-		$this->assertEquals($expectedMissing, $missing);
124
-	}
122
+        $this->assertTrue(is_array($missing));
123
+        $this->assertEquals($expectedMissing, $missing);
124
+    }
125 125
 
126
-	/**
127
-	 * @param $expectedMissing
128
-	 * @param $libs
129
-	 */
130
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesLibs')]
131
-	public function testLibs($expectedMissing, $libs): void {
132
-		$app = [
133
-			'dependencies' => [
134
-			]
135
-		];
136
-		if (!is_null($libs)) {
137
-			$app['dependencies']['lib'] = $libs;
138
-		}
126
+    /**
127
+     * @param $expectedMissing
128
+     * @param $libs
129
+     */
130
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesLibs')]
131
+    public function testLibs($expectedMissing, $libs): void {
132
+        $app = [
133
+            'dependencies' => [
134
+            ]
135
+        ];
136
+        if (!is_null($libs)) {
137
+            $app['dependencies']['lib'] = $libs;
138
+        }
139 139
 
140
-		$missing = $this->analyser->analyze($app);
140
+        $missing = $this->analyser->analyze($app);
141 141
 
142
-		$this->assertTrue(is_array($missing));
143
-		$this->assertEquals($expectedMissing, $missing);
144
-	}
142
+        $this->assertTrue(is_array($missing));
143
+        $this->assertEquals($expectedMissing, $missing);
144
+    }
145 145
 
146
-	/**
147
-	 * @param $expectedMissing
148
-	 * @param $oss
149
-	 */
150
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesOS')]
151
-	public function testOS($expectedMissing, $oss): void {
152
-		$app = [
153
-			'dependencies' => []
154
-		];
155
-		if (!is_null($oss)) {
156
-			$app['dependencies']['os'] = $oss;
157
-		}
146
+    /**
147
+     * @param $expectedMissing
148
+     * @param $oss
149
+     */
150
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesOS')]
151
+    public function testOS($expectedMissing, $oss): void {
152
+        $app = [
153
+            'dependencies' => []
154
+        ];
155
+        if (!is_null($oss)) {
156
+            $app['dependencies']['os'] = $oss;
157
+        }
158 158
 
159
-		$missing = $this->analyser->analyze($app);
159
+        $missing = $this->analyser->analyze($app);
160 160
 
161
-		$this->assertTrue(is_array($missing));
162
-		$this->assertEquals($expectedMissing, $missing);
163
-	}
161
+        $this->assertTrue(is_array($missing));
162
+        $this->assertEquals($expectedMissing, $missing);
163
+    }
164 164
 
165
-	/**
166
-	 * @param $expectedMissing
167
-	 * @param $oc
168
-	 */
169
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesOC')]
170
-	public function testOC($expectedMissing, $oc): void {
171
-		$app = [
172
-			'dependencies' => []
173
-		];
174
-		if (!is_null($oc)) {
175
-			$app['dependencies'] = $oc;
176
-		}
165
+    /**
166
+     * @param $expectedMissing
167
+     * @param $oc
168
+     */
169
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesOC')]
170
+    public function testOC($expectedMissing, $oc): void {
171
+        $app = [
172
+            'dependencies' => []
173
+        ];
174
+        if (!is_null($oc)) {
175
+            $app['dependencies'] = $oc;
176
+        }
177 177
 
178
-		$missing = $this->analyser->analyze($app);
178
+        $missing = $this->analyser->analyze($app);
179 179
 
180
-		$this->assertTrue(is_array($missing));
181
-		$this->assertEquals($expectedMissing, $missing);
182
-	}
180
+        $this->assertTrue(is_array($missing));
181
+        $this->assertEquals($expectedMissing, $missing);
182
+    }
183 183
 
184
-	/**
185
-	 * @return array
186
-	 */
187
-	public static function providesOC(): array {
188
-		return [
189
-			// no version -> no missing dependency
190
-			[
191
-				[],
192
-				null,
193
-			],
194
-			[
195
-				[],
196
-				[
197
-					'nextcloud' => [
198
-						'@attributes' => [
199
-							'min-version' => '8',
200
-							'max-version' => '8',
201
-						],
202
-					],
203
-				],
204
-			],
205
-			[
206
-				[],
207
-				[
208
-					'nextcloud' => [
209
-						'@attributes' => [
210
-							'min-version' => '8.0',
211
-							'max-version' => '8.0',
212
-						],
213
-					],
214
-				],
215
-			],
216
-			[
217
-				[],
218
-				[
219
-					'nextcloud' => [
220
-						'@attributes' => [
221
-							'min-version' => '8.0.2',
222
-							'max-version' => '8.0.2'
223
-						],
224
-					],
225
-				],
226
-			],
227
-			[
228
-				[
229
-					'Server version 8.0.3 or higher is required.',
230
-				],
231
-				[
232
-					'nextcloud' => [
233
-						'@attributes' => [
234
-							'min-version' => '8.0.3'
235
-						],
236
-					],
237
-				],
238
-			],
239
-			[
240
-				[
241
-					'Server version 9 or higher is required.',
242
-				],
243
-				[
244
-					'nextcloud' => [
245
-						'@attributes' => [
246
-							'min-version' => '9'
247
-						],
248
-					],
249
-				],
250
-			],
251
-			[
252
-				[
253
-					'Server version 10 or higher is required.',
254
-				],
255
-				[
256
-					'nextcloud' => [
257
-						'@attributes' => [
258
-							'min-version' => '10'
259
-						],
260
-					],
261
-					'owncloud' => [
262
-						'@attributes' => [
263
-							'min-version' => '9'
264
-						],
265
-					],
266
-				],
267
-			],
268
-			[
269
-				[
270
-					'Server version 9.2 or higher is required.',
271
-				],
272
-				[
273
-					'nextcloud' => [
274
-						'@attributes' => [
275
-							'min-version' => '9.2',
276
-						],
277
-					],
278
-				],
279
-			],
280
-			[
281
-				[
282
-					'Server version 11 or higher is required.',
283
-				],
284
-				[
285
-					'nextcloud' => [
286
-						'@attributes' => [
287
-							'min-version' => '11',
288
-						],
289
-					],
290
-				],
291
-			],
292
-			[
293
-				[
294
-					'Server version 8.0.1 or lower is required.',
295
-				],
296
-				[
297
-					'nextcloud' => [
298
-						'@attributes' => [
299
-							'max-version' => '8.0.1',
300
-						],
301
-					],
302
-				],
303
-			],
304
-			[
305
-				[],
306
-				[
307
-					'owncloud' => [
308
-						'@attributes' => [
309
-							'min-version' => '8',
310
-							'max-version' => '8',
311
-						],
312
-					],
313
-				],
314
-			],
315
-			[
316
-				[],
317
-				[
318
-					'owncloud' => [
319
-						'@attributes' => [
320
-							'min-version' => '8.0',
321
-							'max-version' => '8.0',
322
-						],
323
-					],
324
-				],
325
-			],
326
-			[
327
-				[],
328
-				[
329
-					'owncloud' => [
330
-						'@attributes' => [
331
-							'min-version' => '8.0.2',
332
-							'max-version' => '8.0.2'
333
-						],
334
-					],
335
-				],
336
-			],
337
-			[
338
-				[
339
-					'Server version 8.0.3 or higher is required.',
340
-				],
341
-				[
342
-					'owncloud' => [
343
-						'@attributes' => [
344
-							'min-version' => '8.0.3'
345
-						],
346
-					],
347
-				],
348
-			],
349
-			[
350
-				[
351
-					'Server version 9 or higher is required.',
352
-				],
353
-				[
354
-					'owncloud' => [
355
-						'@attributes' => [
356
-							'min-version' => '9'
357
-						],
358
-					],
359
-				],
360
-			],
361
-			[
362
-				[
363
-					'Server version 9.2 or higher is required.',
364
-				],
365
-				[
366
-					'owncloud' => [
367
-						'@attributes' => [
368
-							'min-version' => '9.2',
369
-						],
370
-					],
371
-				],
372
-			],
373
-			[
374
-				[
375
-					'Server version 8.0.1 or lower is required.',
376
-				],
377
-				[
378
-					'owncloud' => [
379
-						'@attributes' => [
380
-							'max-version' => '8.0.1',
381
-						],
382
-					],
383
-				],
384
-			],
385
-		];
386
-	}
184
+    /**
185
+     * @return array
186
+     */
187
+    public static function providesOC(): array {
188
+        return [
189
+            // no version -> no missing dependency
190
+            [
191
+                [],
192
+                null,
193
+            ],
194
+            [
195
+                [],
196
+                [
197
+                    'nextcloud' => [
198
+                        '@attributes' => [
199
+                            'min-version' => '8',
200
+                            'max-version' => '8',
201
+                        ],
202
+                    ],
203
+                ],
204
+            ],
205
+            [
206
+                [],
207
+                [
208
+                    'nextcloud' => [
209
+                        '@attributes' => [
210
+                            'min-version' => '8.0',
211
+                            'max-version' => '8.0',
212
+                        ],
213
+                    ],
214
+                ],
215
+            ],
216
+            [
217
+                [],
218
+                [
219
+                    'nextcloud' => [
220
+                        '@attributes' => [
221
+                            'min-version' => '8.0.2',
222
+                            'max-version' => '8.0.2'
223
+                        ],
224
+                    ],
225
+                ],
226
+            ],
227
+            [
228
+                [
229
+                    'Server version 8.0.3 or higher is required.',
230
+                ],
231
+                [
232
+                    'nextcloud' => [
233
+                        '@attributes' => [
234
+                            'min-version' => '8.0.3'
235
+                        ],
236
+                    ],
237
+                ],
238
+            ],
239
+            [
240
+                [
241
+                    'Server version 9 or higher is required.',
242
+                ],
243
+                [
244
+                    'nextcloud' => [
245
+                        '@attributes' => [
246
+                            'min-version' => '9'
247
+                        ],
248
+                    ],
249
+                ],
250
+            ],
251
+            [
252
+                [
253
+                    'Server version 10 or higher is required.',
254
+                ],
255
+                [
256
+                    'nextcloud' => [
257
+                        '@attributes' => [
258
+                            'min-version' => '10'
259
+                        ],
260
+                    ],
261
+                    'owncloud' => [
262
+                        '@attributes' => [
263
+                            'min-version' => '9'
264
+                        ],
265
+                    ],
266
+                ],
267
+            ],
268
+            [
269
+                [
270
+                    'Server version 9.2 or higher is required.',
271
+                ],
272
+                [
273
+                    'nextcloud' => [
274
+                        '@attributes' => [
275
+                            'min-version' => '9.2',
276
+                        ],
277
+                    ],
278
+                ],
279
+            ],
280
+            [
281
+                [
282
+                    'Server version 11 or higher is required.',
283
+                ],
284
+                [
285
+                    'nextcloud' => [
286
+                        '@attributes' => [
287
+                            'min-version' => '11',
288
+                        ],
289
+                    ],
290
+                ],
291
+            ],
292
+            [
293
+                [
294
+                    'Server version 8.0.1 or lower is required.',
295
+                ],
296
+                [
297
+                    'nextcloud' => [
298
+                        '@attributes' => [
299
+                            'max-version' => '8.0.1',
300
+                        ],
301
+                    ],
302
+                ],
303
+            ],
304
+            [
305
+                [],
306
+                [
307
+                    'owncloud' => [
308
+                        '@attributes' => [
309
+                            'min-version' => '8',
310
+                            'max-version' => '8',
311
+                        ],
312
+                    ],
313
+                ],
314
+            ],
315
+            [
316
+                [],
317
+                [
318
+                    'owncloud' => [
319
+                        '@attributes' => [
320
+                            'min-version' => '8.0',
321
+                            'max-version' => '8.0',
322
+                        ],
323
+                    ],
324
+                ],
325
+            ],
326
+            [
327
+                [],
328
+                [
329
+                    'owncloud' => [
330
+                        '@attributes' => [
331
+                            'min-version' => '8.0.2',
332
+                            'max-version' => '8.0.2'
333
+                        ],
334
+                    ],
335
+                ],
336
+            ],
337
+            [
338
+                [
339
+                    'Server version 8.0.3 or higher is required.',
340
+                ],
341
+                [
342
+                    'owncloud' => [
343
+                        '@attributes' => [
344
+                            'min-version' => '8.0.3'
345
+                        ],
346
+                    ],
347
+                ],
348
+            ],
349
+            [
350
+                [
351
+                    'Server version 9 or higher is required.',
352
+                ],
353
+                [
354
+                    'owncloud' => [
355
+                        '@attributes' => [
356
+                            'min-version' => '9'
357
+                        ],
358
+                    ],
359
+                ],
360
+            ],
361
+            [
362
+                [
363
+                    'Server version 9.2 or higher is required.',
364
+                ],
365
+                [
366
+                    'owncloud' => [
367
+                        '@attributes' => [
368
+                            'min-version' => '9.2',
369
+                        ],
370
+                    ],
371
+                ],
372
+            ],
373
+            [
374
+                [
375
+                    'Server version 8.0.1 or lower is required.',
376
+                ],
377
+                [
378
+                    'owncloud' => [
379
+                        '@attributes' => [
380
+                            'max-version' => '8.0.1',
381
+                        ],
382
+                    ],
383
+                ],
384
+            ],
385
+        ];
386
+    }
387 387
 
388
-	/**
389
-	 * @return array
390
-	 */
391
-	public static function providesOS(): array {
392
-		return [
393
-			[[], null],
394
-			[[], []],
395
-			[['The following platforms are supported: ANDROID'], 'ANDROID'],
396
-			[['The following platforms are supported: WINNT'], ['WINNT']]
397
-		];
398
-	}
388
+    /**
389
+     * @return array
390
+     */
391
+    public static function providesOS(): array {
392
+        return [
393
+            [[], null],
394
+            [[], []],
395
+            [['The following platforms are supported: ANDROID'], 'ANDROID'],
396
+            [['The following platforms are supported: WINNT'], ['WINNT']]
397
+        ];
398
+    }
399 399
 
400
-	/**
401
-	 * @return array
402
-	 */
403
-	public static function providesLibs(): array {
404
-		return [
405
-			// we expect curl to exist
406
-			[[], 'curl'],
407
-			// we expect abcde to exist
408
-			[['The library abcde is not available.'], ['abcde']],
409
-			// curl in version 100.0 does not exist
410
-			[['Library curl with a version higher than 100.0 is required - available version 2.3.4.'],
411
-				[['@attributes' => ['min-version' => '100.0'], '@value' => 'curl']]],
412
-			// curl in version 100.0 does not exist
413
-			[['Library curl with a version lower than 1.0.0 is required - available version 2.3.4.'],
414
-				[['@attributes' => ['max-version' => '1.0.0'], '@value' => 'curl']]],
415
-			[['Library curl with a version lower than 2.3.3 is required - available version 2.3.4.'],
416
-				[['@attributes' => ['max-version' => '2.3.3'], '@value' => 'curl']]],
417
-			[['Library curl with a version higher than 2.3.5 is required - available version 2.3.4.'],
418
-				[['@attributes' => ['min-version' => '2.3.5'], '@value' => 'curl']]],
419
-			[[],
420
-				[['@attributes' => ['min-version' => '2.3.4', 'max-version' => '2.3.4'], '@value' => 'curl']]],
421
-			[[],
422
-				[['@attributes' => ['min-version' => '2.3', 'max-version' => '2.3'], '@value' => 'curl']]],
423
-			[[],
424
-				[['@attributes' => ['min-version' => '2', 'max-version' => '2'], '@value' => 'curl']]],
425
-			[[],
426
-				['@attributes' => ['min-version' => '2', 'max-version' => '2'], '@value' => 'curl']],
427
-		];
428
-	}
400
+    /**
401
+     * @return array
402
+     */
403
+    public static function providesLibs(): array {
404
+        return [
405
+            // we expect curl to exist
406
+            [[], 'curl'],
407
+            // we expect abcde to exist
408
+            [['The library abcde is not available.'], ['abcde']],
409
+            // curl in version 100.0 does not exist
410
+            [['Library curl with a version higher than 100.0 is required - available version 2.3.4.'],
411
+                [['@attributes' => ['min-version' => '100.0'], '@value' => 'curl']]],
412
+            // curl in version 100.0 does not exist
413
+            [['Library curl with a version lower than 1.0.0 is required - available version 2.3.4.'],
414
+                [['@attributes' => ['max-version' => '1.0.0'], '@value' => 'curl']]],
415
+            [['Library curl with a version lower than 2.3.3 is required - available version 2.3.4.'],
416
+                [['@attributes' => ['max-version' => '2.3.3'], '@value' => 'curl']]],
417
+            [['Library curl with a version higher than 2.3.5 is required - available version 2.3.4.'],
418
+                [['@attributes' => ['min-version' => '2.3.5'], '@value' => 'curl']]],
419
+            [[],
420
+                [['@attributes' => ['min-version' => '2.3.4', 'max-version' => '2.3.4'], '@value' => 'curl']]],
421
+            [[],
422
+                [['@attributes' => ['min-version' => '2.3', 'max-version' => '2.3'], '@value' => 'curl']]],
423
+            [[],
424
+                [['@attributes' => ['min-version' => '2', 'max-version' => '2'], '@value' => 'curl']]],
425
+            [[],
426
+                ['@attributes' => ['min-version' => '2', 'max-version' => '2'], '@value' => 'curl']],
427
+        ];
428
+    }
429 429
 
430
-	/**
431
-	 * @return array
432
-	 */
433
-	public static function providesCommands(): array {
434
-		return [
435
-			[[], null],
436
-			// grep is known on linux
437
-			[[], [['@attributes' => ['os' => 'Linux'], '@value' => 'grep']]],
438
-			// grepp is not known on linux
439
-			[['The command line tool grepp could not be found'], [['@attributes' => ['os' => 'Linux'], '@value' => 'grepp']]],
440
-			// we don't care about tools on Windows - we are on Linux
441
-			[[], [['@attributes' => ['os' => 'Windows'], '@value' => 'grepp']]],
442
-			// grep is known on all systems
443
-			[[], 'grep'],
444
-			[[], ['@attributes' => ['os' => 'Linux'], '@value' => 'grep']],
445
-		];
446
-	}
430
+    /**
431
+     * @return array
432
+     */
433
+    public static function providesCommands(): array {
434
+        return [
435
+            [[], null],
436
+            // grep is known on linux
437
+            [[], [['@attributes' => ['os' => 'Linux'], '@value' => 'grep']]],
438
+            // grepp is not known on linux
439
+            [['The command line tool grepp could not be found'], [['@attributes' => ['os' => 'Linux'], '@value' => 'grepp']]],
440
+            // we don't care about tools on Windows - we are on Linux
441
+            [[], [['@attributes' => ['os' => 'Windows'], '@value' => 'grepp']]],
442
+            // grep is known on all systems
443
+            [[], 'grep'],
444
+            [[], ['@attributes' => ['os' => 'Linux'], '@value' => 'grep']],
445
+        ];
446
+    }
447 447
 
448
-	/**
449
-	 * @return array
450
-	 */
451
-	public static function providesDatabases(): array {
452
-		return [
453
-			// non BC - in case on databases are defined -> all are supported
454
-			[[], null],
455
-			[[], []],
456
-			[['The following databases are supported: mongodb'], 'mongodb'],
457
-			[['The following databases are supported: sqlite, postgres'], ['sqlite', ['@value' => 'postgres']]],
458
-		];
459
-	}
448
+    /**
449
+     * @return array
450
+     */
451
+    public static function providesDatabases(): array {
452
+        return [
453
+            // non BC - in case on databases are defined -> all are supported
454
+            [[], null],
455
+            [[], []],
456
+            [['The following databases are supported: mongodb'], 'mongodb'],
457
+            [['The following databases are supported: sqlite, postgres'], ['sqlite', ['@value' => 'postgres']]],
458
+        ];
459
+    }
460 460
 
461
-	/**
462
-	 * @return array
463
-	 */
464
-	public static function providesPhpVersion(): array {
465
-		return [
466
-			[[], null, null, null],
467
-			[[], '5.4', null, null],
468
-			[[], null, '5.5', null],
469
-			[[], '5.4', '5.5', null],
470
-			[['PHP 5.4.4 or higher is required.'], '5.4.4', null, null],
471
-			[['PHP with a version lower than 5.4.2 is required.'], null, '5.4.2', null],
472
-			[['64bit or higher PHP required.'], null, null, 64],
473
-			[[], '5.4', '5.4', null],
474
-		];
475
-	}
461
+    /**
462
+     * @return array
463
+     */
464
+    public static function providesPhpVersion(): array {
465
+        return [
466
+            [[], null, null, null],
467
+            [[], '5.4', null, null],
468
+            [[], null, '5.5', null],
469
+            [[], '5.4', '5.5', null],
470
+            [['PHP 5.4.4 or higher is required.'], '5.4.4', null, null],
471
+            [['PHP with a version lower than 5.4.2 is required.'], null, '5.4.2', null],
472
+            [['64bit or higher PHP required.'], null, null, 64],
473
+            [[], '5.4', '5.4', null],
474
+        ];
475
+    }
476 476
 
477
-	public static function appVersionsProvider(): array {
478
-		return [
479
-			// exact match
480
-			[
481
-				'6.0.0.0',
482
-				[
483
-					'requiremin' => '6.0',
484
-					'requiremax' => '6.0',
485
-				],
486
-				true
487
-			],
488
-			// in-between match
489
-			[
490
-				'6.0.0.0',
491
-				[
492
-					'requiremin' => '5.0',
493
-					'requiremax' => '7.0',
494
-				],
495
-				true
496
-			],
497
-			// app too old
498
-			[
499
-				'6.0.0.0',
500
-				[
501
-					'requiremin' => '5.0',
502
-					'requiremax' => '5.0',
503
-				],
504
-				false
505
-			],
506
-			// app too new
507
-			[
508
-				'5.0.0.0',
509
-				[
510
-					'requiremin' => '6.0',
511
-					'requiremax' => '6.0',
512
-				],
513
-				false
514
-			],
515
-			// only min specified
516
-			[
517
-				'6.0.0.0',
518
-				[
519
-					'requiremin' => '6.0',
520
-				],
521
-				true
522
-			],
523
-			// only min specified fail
524
-			[
525
-				'5.0.0.0',
526
-				[
527
-					'requiremin' => '6.0',
528
-				],
529
-				false
530
-			],
531
-			// only min specified legacy
532
-			[
533
-				'6.0.0.0',
534
-				[
535
-					'require' => '6.0',
536
-				],
537
-				true
538
-			],
539
-			// only min specified legacy fail
540
-			[
541
-				'4.0.0.0',
542
-				[
543
-					'require' => '6.0',
544
-				],
545
-				false
546
-			],
547
-			// only max specified
548
-			[
549
-				'5.0.0.0',
550
-				[
551
-					'requiremax' => '6.0',
552
-				],
553
-				true
554
-			],
555
-			// only max specified fail
556
-			[
557
-				'7.0.0.0',
558
-				[
559
-					'requiremax' => '6.0',
560
-				],
561
-				false
562
-			],
563
-			// variations of versions
564
-			// single OC number
565
-			[
566
-				'4',
567
-				[
568
-					'require' => '4.0',
569
-				],
570
-				true
571
-			],
572
-			// multiple OC number
573
-			[
574
-				'4.3.1',
575
-				[
576
-					'require' => '4.3',
577
-				],
578
-				true
579
-			],
580
-			// single app number
581
-			[
582
-				'4',
583
-				[
584
-					'require' => '4',
585
-				],
586
-				true
587
-			],
588
-			// single app number fail
589
-			[
590
-				'4.3',
591
-				[
592
-					'require' => '5',
593
-				],
594
-				false
595
-			],
596
-			// complex
597
-			[
598
-				'5.0.0',
599
-				[
600
-					'require' => '4.5.1',
601
-				],
602
-				true
603
-			],
604
-			// complex fail
605
-			[
606
-				'4.3.1',
607
-				[
608
-					'require' => '4.3.2',
609
-				],
610
-				false
611
-			],
612
-			// two numbers
613
-			[
614
-				'4.3.1',
615
-				[
616
-					'require' => '4.4',
617
-				],
618
-				false
619
-			],
620
-			// one number fail
621
-			[
622
-				'4.3.1',
623
-				[
624
-					'require' => '5',
625
-				],
626
-				false
627
-			],
628
-			// pre-alpha app
629
-			[
630
-				'5.0.3',
631
-				[
632
-					'require' => '4.93',
633
-				],
634
-				true
635
-			],
636
-			// pre-alpha OC
637
-			[
638
-				'6.90.0.2',
639
-				[
640
-					'require' => '6.90',
641
-				],
642
-				true
643
-			],
644
-			// pre-alpha OC max
645
-			[
646
-				'6.90.0.2',
647
-				[
648
-					'requiremax' => '7',
649
-				],
650
-				true
651
-			],
652
-			// expect same major number match
653
-			[
654
-				'5.0.3',
655
-				[
656
-					'require' => '5',
657
-				],
658
-				true
659
-			],
660
-			// expect same major number match
661
-			[
662
-				'5.0.3',
663
-				[
664
-					'requiremax' => '5',
665
-				],
666
-				true
667
-			],
668
-			// dependencies versions before require*
669
-			[
670
-				'6.0.0.0',
671
-				[
672
-					'requiremin' => '5.0',
673
-					'requiremax' => '7.0',
674
-					'dependencies' => [
675
-						'owncloud' => [
676
-							'@attributes' => [
677
-								'min-version' => '7.0',
678
-								'max-version' => '7.0',
679
-							],
680
-						],
681
-					],
682
-				],
683
-				false
684
-			],
685
-			[
686
-				'6.0.0.0',
687
-				[
688
-					'requiremin' => '5.0',
689
-					'requiremax' => '7.0',
690
-					'dependencies' => [
691
-						'owncloud' => [
692
-							'@attributes' => [
693
-								'min-version' => '5.0',
694
-								'max-version' => '5.0',
695
-							],
696
-						],
697
-					],
698
-				],
699
-				false
700
-			],
701
-			[
702
-				'6.0.0.0',
703
-				[
704
-					'requiremin' => '5.0',
705
-					'requiremax' => '5.0',
706
-					'dependencies' => [
707
-						'owncloud' => [
708
-							'@attributes' => [
709
-								'min-version' => '5.0',
710
-								'max-version' => '7.0',
711
-							],
712
-						],
713
-					],
714
-				],
715
-				true
716
-			],
717
-			[
718
-				'9.2.0.0',
719
-				[
720
-					'dependencies' => [
721
-						'owncloud' => [
722
-							'@attributes' => [
723
-								'min-version' => '9.0',
724
-								'max-version' => '9.1',
725
-							],
726
-						],
727
-						'nextcloud' => [
728
-							'@attributes' => [
729
-								'min-version' => '9.1',
730
-								'max-version' => '9.2',
731
-							],
732
-						],
733
-					],
734
-				],
735
-				true
736
-			],
737
-			[
738
-				'9.2.0.0',
739
-				[
740
-					'dependencies' => [
741
-						'nextcloud' => [
742
-							'@attributes' => [
743
-								'min-version' => '9.1',
744
-								'max-version' => '9.2',
745
-							],
746
-						],
747
-					],
748
-				],
749
-				true
750
-			],
751
-		];
752
-	}
477
+    public static function appVersionsProvider(): array {
478
+        return [
479
+            // exact match
480
+            [
481
+                '6.0.0.0',
482
+                [
483
+                    'requiremin' => '6.0',
484
+                    'requiremax' => '6.0',
485
+                ],
486
+                true
487
+            ],
488
+            // in-between match
489
+            [
490
+                '6.0.0.0',
491
+                [
492
+                    'requiremin' => '5.0',
493
+                    'requiremax' => '7.0',
494
+                ],
495
+                true
496
+            ],
497
+            // app too old
498
+            [
499
+                '6.0.0.0',
500
+                [
501
+                    'requiremin' => '5.0',
502
+                    'requiremax' => '5.0',
503
+                ],
504
+                false
505
+            ],
506
+            // app too new
507
+            [
508
+                '5.0.0.0',
509
+                [
510
+                    'requiremin' => '6.0',
511
+                    'requiremax' => '6.0',
512
+                ],
513
+                false
514
+            ],
515
+            // only min specified
516
+            [
517
+                '6.0.0.0',
518
+                [
519
+                    'requiremin' => '6.0',
520
+                ],
521
+                true
522
+            ],
523
+            // only min specified fail
524
+            [
525
+                '5.0.0.0',
526
+                [
527
+                    'requiremin' => '6.0',
528
+                ],
529
+                false
530
+            ],
531
+            // only min specified legacy
532
+            [
533
+                '6.0.0.0',
534
+                [
535
+                    'require' => '6.0',
536
+                ],
537
+                true
538
+            ],
539
+            // only min specified legacy fail
540
+            [
541
+                '4.0.0.0',
542
+                [
543
+                    'require' => '6.0',
544
+                ],
545
+                false
546
+            ],
547
+            // only max specified
548
+            [
549
+                '5.0.0.0',
550
+                [
551
+                    'requiremax' => '6.0',
552
+                ],
553
+                true
554
+            ],
555
+            // only max specified fail
556
+            [
557
+                '7.0.0.0',
558
+                [
559
+                    'requiremax' => '6.0',
560
+                ],
561
+                false
562
+            ],
563
+            // variations of versions
564
+            // single OC number
565
+            [
566
+                '4',
567
+                [
568
+                    'require' => '4.0',
569
+                ],
570
+                true
571
+            ],
572
+            // multiple OC number
573
+            [
574
+                '4.3.1',
575
+                [
576
+                    'require' => '4.3',
577
+                ],
578
+                true
579
+            ],
580
+            // single app number
581
+            [
582
+                '4',
583
+                [
584
+                    'require' => '4',
585
+                ],
586
+                true
587
+            ],
588
+            // single app number fail
589
+            [
590
+                '4.3',
591
+                [
592
+                    'require' => '5',
593
+                ],
594
+                false
595
+            ],
596
+            // complex
597
+            [
598
+                '5.0.0',
599
+                [
600
+                    'require' => '4.5.1',
601
+                ],
602
+                true
603
+            ],
604
+            // complex fail
605
+            [
606
+                '4.3.1',
607
+                [
608
+                    'require' => '4.3.2',
609
+                ],
610
+                false
611
+            ],
612
+            // two numbers
613
+            [
614
+                '4.3.1',
615
+                [
616
+                    'require' => '4.4',
617
+                ],
618
+                false
619
+            ],
620
+            // one number fail
621
+            [
622
+                '4.3.1',
623
+                [
624
+                    'require' => '5',
625
+                ],
626
+                false
627
+            ],
628
+            // pre-alpha app
629
+            [
630
+                '5.0.3',
631
+                [
632
+                    'require' => '4.93',
633
+                ],
634
+                true
635
+            ],
636
+            // pre-alpha OC
637
+            [
638
+                '6.90.0.2',
639
+                [
640
+                    'require' => '6.90',
641
+                ],
642
+                true
643
+            ],
644
+            // pre-alpha OC max
645
+            [
646
+                '6.90.0.2',
647
+                [
648
+                    'requiremax' => '7',
649
+                ],
650
+                true
651
+            ],
652
+            // expect same major number match
653
+            [
654
+                '5.0.3',
655
+                [
656
+                    'require' => '5',
657
+                ],
658
+                true
659
+            ],
660
+            // expect same major number match
661
+            [
662
+                '5.0.3',
663
+                [
664
+                    'requiremax' => '5',
665
+                ],
666
+                true
667
+            ],
668
+            // dependencies versions before require*
669
+            [
670
+                '6.0.0.0',
671
+                [
672
+                    'requiremin' => '5.0',
673
+                    'requiremax' => '7.0',
674
+                    'dependencies' => [
675
+                        'owncloud' => [
676
+                            '@attributes' => [
677
+                                'min-version' => '7.0',
678
+                                'max-version' => '7.0',
679
+                            ],
680
+                        ],
681
+                    ],
682
+                ],
683
+                false
684
+            ],
685
+            [
686
+                '6.0.0.0',
687
+                [
688
+                    'requiremin' => '5.0',
689
+                    'requiremax' => '7.0',
690
+                    'dependencies' => [
691
+                        'owncloud' => [
692
+                            '@attributes' => [
693
+                                'min-version' => '5.0',
694
+                                'max-version' => '5.0',
695
+                            ],
696
+                        ],
697
+                    ],
698
+                ],
699
+                false
700
+            ],
701
+            [
702
+                '6.0.0.0',
703
+                [
704
+                    'requiremin' => '5.0',
705
+                    'requiremax' => '5.0',
706
+                    'dependencies' => [
707
+                        'owncloud' => [
708
+                            '@attributes' => [
709
+                                'min-version' => '5.0',
710
+                                'max-version' => '7.0',
711
+                            ],
712
+                        ],
713
+                    ],
714
+                ],
715
+                true
716
+            ],
717
+            [
718
+                '9.2.0.0',
719
+                [
720
+                    'dependencies' => [
721
+                        'owncloud' => [
722
+                            '@attributes' => [
723
+                                'min-version' => '9.0',
724
+                                'max-version' => '9.1',
725
+                            ],
726
+                        ],
727
+                        'nextcloud' => [
728
+                            '@attributes' => [
729
+                                'min-version' => '9.1',
730
+                                'max-version' => '9.2',
731
+                            ],
732
+                        ],
733
+                    ],
734
+                ],
735
+                true
736
+            ],
737
+            [
738
+                '9.2.0.0',
739
+                [
740
+                    'dependencies' => [
741
+                        'nextcloud' => [
742
+                            '@attributes' => [
743
+                                'min-version' => '9.1',
744
+                                'max-version' => '9.2',
745
+                            ],
746
+                        ],
747
+                    ],
748
+                ],
749
+                true
750
+            ],
751
+        ];
752
+    }
753 753
 
754
-	#[\PHPUnit\Framework\Attributes\DataProvider('appVersionsProvider')]
755
-	public function testServerVersion($ncVersion, $appInfo, $expectedResult): void {
756
-		$this->assertEquals($expectedResult, count($this->analyser->analyzeServerVersion($ncVersion, $appInfo, false)) === 0);
757
-	}
754
+    #[\PHPUnit\Framework\Attributes\DataProvider('appVersionsProvider')]
755
+    public function testServerVersion($ncVersion, $appInfo, $expectedResult): void {
756
+        $this->assertEquals($expectedResult, count($this->analyser->analyzeServerVersion($ncVersion, $appInfo, false)) === 0);
757
+    }
758 758
 }
Please login to merge, or discard this patch.
tests/lib/App/PlatformRepositoryTest.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -12,50 +12,50 @@
 block discarded – undo
12 12
 use OC\App\PlatformRepository;
13 13
 
14 14
 class PlatformRepositoryTest extends \Test\TestCase {
15
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesVersions')]
16
-	public function testVersion(string $input, string $expected): void {
17
-		$pr = new PlatformRepository();
18
-		$normalizedVersion = $pr->normalizeVersion($input);
19
-		$this->assertEquals($expected, $normalizedVersion);
20
-	}
15
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesVersions')]
16
+    public function testVersion(string $input, string $expected): void {
17
+        $pr = new PlatformRepository();
18
+        $normalizedVersion = $pr->normalizeVersion($input);
19
+        $this->assertEquals($expected, $normalizedVersion);
20
+    }
21 21
 
22
-	public static function providesVersions(): array {
23
-		return [
24
-			'none' => ['1.0.0', '1.0.0.0'],
25
-			'none/2' => ['1.2.3.4', '1.2.3.4'],
26
-			'parses state' => ['1.0.0RC1dev', '1.0.0.0-RC1-dev'],
27
-			'CI parsing' => ['1.0.0-rC15-dev', '1.0.0.0-RC15-dev'],
28
-			'delimiters' => ['1.0.0.RC.15-dev', '1.0.0.0-RC15-dev'],
29
-			'RC uppercase' => ['1.0.0-rc1', '1.0.0.0-RC1'],
30
-			'patch replace' => ['1.0.0.pl3-dev', '1.0.0.0-patch3-dev'],
31
-			'forces w.x.y.z' => ['1.0-dev', '1.0.0.0-dev'],
32
-			'forces w.x.y.z/2' => ['0', '0.0.0.0'],
33
-			'parses long' => ['10.4.13-beta', '10.4.13.0-beta'],
34
-			'parses long/2' => ['10.4.13beta2', '10.4.13.0-beta2'],
35
-			'parses long/semver' => ['10.4.13beta.2', '10.4.13.0-beta2'],
36
-			'expand shorthand' => ['10.4.13-b', '10.4.13.0-beta'],
37
-			'expand shorthand2' => ['10.4.13-b5', '10.4.13.0-beta5'],
38
-			'strips leading v' => ['v1.0.0', '1.0.0.0'],
39
-			'strips v/datetime' => ['v20100102', '20100102'],
40
-			'parses dates y-m' => ['2010.01', '2010-01'],
41
-			'parses dates w/ .' => ['2010.01.02', '2010-01-02'],
42
-			'parses dates w/ -' => ['2010-01-02', '2010-01-02'],
43
-			'parses numbers' => ['2010-01-02.5', '2010-01-02-5'],
44
-			'parses dates y.m.Y' => ['2010.1.555', '2010.1.555.0'],
45
-			'parses datetime' => ['20100102-203040', '20100102-203040'],
46
-			'parses dt+number' => ['20100102203040-10', '20100102203040-10'],
47
-			'parses dt+patch' => ['20100102-203040-p1', '20100102-203040-patch1'],
48
-			'parses master' => ['dev-master', '9999999-dev'],
49
-			'parses trunk' => ['dev-trunk', '9999999-dev'],
50
-			//			'parses branches' => array('1.x-dev', '1.9999999.9999999.9999999-dev'),
51
-			'parses arbitrary' => ['dev-feature-foo', 'dev-feature-foo'],
52
-			'parses arbitrary2' => ['DEV-FOOBAR', 'dev-FOOBAR'],
53
-			'parses arbitrary3' => ['dev-feature/foo', 'dev-feature/foo'],
54
-			'ignores aliases' => ['dev-master as 1.0.0', '9999999-dev'],
55
-			//			'semver metadata' => array('dev-master+foo.bar', '9999999-dev'),
56
-			//			'semver metadata/2' => array('1.0.0-beta.5+foo', '1.0.0.0-beta5'),
57
-			//			'semver metadata/3' => array('1.0.0+foo', '1.0.0.0'),
58
-			//			'metadata w/ alias' => array('1.0.0+foo as 2.0', '1.0.0.0'),
59
-		];
60
-	}
22
+    public static function providesVersions(): array {
23
+        return [
24
+            'none' => ['1.0.0', '1.0.0.0'],
25
+            'none/2' => ['1.2.3.4', '1.2.3.4'],
26
+            'parses state' => ['1.0.0RC1dev', '1.0.0.0-RC1-dev'],
27
+            'CI parsing' => ['1.0.0-rC15-dev', '1.0.0.0-RC15-dev'],
28
+            'delimiters' => ['1.0.0.RC.15-dev', '1.0.0.0-RC15-dev'],
29
+            'RC uppercase' => ['1.0.0-rc1', '1.0.0.0-RC1'],
30
+            'patch replace' => ['1.0.0.pl3-dev', '1.0.0.0-patch3-dev'],
31
+            'forces w.x.y.z' => ['1.0-dev', '1.0.0.0-dev'],
32
+            'forces w.x.y.z/2' => ['0', '0.0.0.0'],
33
+            'parses long' => ['10.4.13-beta', '10.4.13.0-beta'],
34
+            'parses long/2' => ['10.4.13beta2', '10.4.13.0-beta2'],
35
+            'parses long/semver' => ['10.4.13beta.2', '10.4.13.0-beta2'],
36
+            'expand shorthand' => ['10.4.13-b', '10.4.13.0-beta'],
37
+            'expand shorthand2' => ['10.4.13-b5', '10.4.13.0-beta5'],
38
+            'strips leading v' => ['v1.0.0', '1.0.0.0'],
39
+            'strips v/datetime' => ['v20100102', '20100102'],
40
+            'parses dates y-m' => ['2010.01', '2010-01'],
41
+            'parses dates w/ .' => ['2010.01.02', '2010-01-02'],
42
+            'parses dates w/ -' => ['2010-01-02', '2010-01-02'],
43
+            'parses numbers' => ['2010-01-02.5', '2010-01-02-5'],
44
+            'parses dates y.m.Y' => ['2010.1.555', '2010.1.555.0'],
45
+            'parses datetime' => ['20100102-203040', '20100102-203040'],
46
+            'parses dt+number' => ['20100102203040-10', '20100102203040-10'],
47
+            'parses dt+patch' => ['20100102-203040-p1', '20100102-203040-patch1'],
48
+            'parses master' => ['dev-master', '9999999-dev'],
49
+            'parses trunk' => ['dev-trunk', '9999999-dev'],
50
+            //			'parses branches' => array('1.x-dev', '1.9999999.9999999.9999999-dev'),
51
+            'parses arbitrary' => ['dev-feature-foo', 'dev-feature-foo'],
52
+            'parses arbitrary2' => ['DEV-FOOBAR', 'dev-FOOBAR'],
53
+            'parses arbitrary3' => ['dev-feature/foo', 'dev-feature/foo'],
54
+            'ignores aliases' => ['dev-master as 1.0.0', '9999999-dev'],
55
+            //			'semver metadata' => array('dev-master+foo.bar', '9999999-dev'),
56
+            //			'semver metadata/2' => array('1.0.0-beta.5+foo', '1.0.0.0-beta5'),
57
+            //			'semver metadata/3' => array('1.0.0+foo', '1.0.0.0'),
58
+            //			'metadata w/ alias' => array('1.0.0+foo as 2.0', '1.0.0.0'),
59
+        ];
60
+    }
61 61
 }
Please login to merge, or discard this patch.
tests/lib/App/InfoParserTest.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -15,96 +15,96 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class InfoParserTest extends TestCase {
18
-	private static CappedMemoryCache $cache;
18
+    private static CappedMemoryCache $cache;
19 19
 
20
-	public static function setUpBeforeClass(): void {
21
-		self::$cache = new CappedMemoryCache();
22
-	}
20
+    public static function setUpBeforeClass(): void {
21
+        self::$cache = new CappedMemoryCache();
22
+    }
23 23
 
24
-	public function parserTest($expectedJson, $xmlFile, $cache = null) {
25
-		$parser = new InfoParser($cache);
24
+    public function parserTest($expectedJson, $xmlFile, $cache = null) {
25
+        $parser = new InfoParser($cache);
26 26
 
27
-		$expectedData = null;
28
-		if (!is_null($expectedJson)) {
29
-			$expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
30
-		}
31
-		$data = $parser->parse(OC::$SERVERROOT . "/tests/data/app/$xmlFile");
27
+        $expectedData = null;
28
+        if (!is_null($expectedJson)) {
29
+            $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
30
+        }
31
+        $data = $parser->parse(OC::$SERVERROOT . "/tests/data/app/$xmlFile");
32 32
 
33
-		$this->assertEquals($expectedData, $data);
34
-	}
33
+        $this->assertEquals($expectedData, $data);
34
+    }
35 35
 
36
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
37
-	public function testParsingValidXmlWithoutCache($expectedJson, $xmlFile): void {
38
-		$this->parserTest($expectedJson, $xmlFile);
39
-	}
36
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
37
+    public function testParsingValidXmlWithoutCache($expectedJson, $xmlFile): void {
38
+        $this->parserTest($expectedJson, $xmlFile);
39
+    }
40 40
 
41
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
42
-	public function testParsingValidXmlWithCache($expectedJson, $xmlFile): void {
43
-		$this->parserTest($expectedJson, $xmlFile, self::$cache);
44
-	}
41
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
42
+    public function testParsingValidXmlWithCache($expectedJson, $xmlFile): void {
43
+        $this->parserTest($expectedJson, $xmlFile, self::$cache);
44
+    }
45 45
 
46
-	public static function providesInfoXml(): array {
47
-		return [
48
-			['expected-info.json', 'valid-info.xml'],
49
-			[null, 'invalid-info.xml'],
50
-			['expected-info.json', 'valid-info.xml'],
51
-			[null, 'invalid-info.xml'],
52
-			['navigation-one-item.json', 'navigation-one-item.xml'],
53
-			['navigation-two-items.json', 'navigation-two-items.xml'],
54
-			['various-single-item.json', 'various-single-item.xml'],
55
-		];
56
-	}
46
+    public static function providesInfoXml(): array {
47
+        return [
48
+            ['expected-info.json', 'valid-info.xml'],
49
+            [null, 'invalid-info.xml'],
50
+            ['expected-info.json', 'valid-info.xml'],
51
+            [null, 'invalid-info.xml'],
52
+            ['navigation-one-item.json', 'navigation-one-item.xml'],
53
+            ['navigation-two-items.json', 'navigation-two-items.xml'],
54
+            ['various-single-item.json', 'various-single-item.xml'],
55
+        ];
56
+    }
57 57
 
58
-	/**
59
-	 * Providers for the app data values
60
-	 */
61
-	public static function appDataProvider(): array {
62
-		return [
63
-			[
64
-				['description' => " \t  This is a multiline \n test with \n \t \n \n some new lines   "],
65
-				['description' => "This is a multiline \n test with \n \t \n \n some new lines"],
66
-			],
67
-			[
68
-				['description' => " \t  This is a multiline \n test with \n \t   some new lines   "],
69
-				['description' => "This is a multiline \n test with \n \t   some new lines"],
70
-			],
71
-			[
72
-				['description' => hex2bin('5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d')],
73
-				['description' => "Permet de s'authentifier dans piwigo directement avec ses identifiants owncloud sans les retaper et met à jours ceux ci en cas de changement de mot de passe."],
74
-			],
75
-			[
76
-				['not-a-description' => " \t  This is a multiline \n test with \n \t   some new lines   "],
77
-				[
78
-					'not-a-description' => " \t  This is a multiline \n test with \n \t   some new lines   ",
79
-					'description' => '',
80
-				],
81
-			],
82
-			[
83
-				['description' => [100, 'bla']],
84
-				['description' => ''],
85
-			],
86
-		];
87
-	}
58
+    /**
59
+     * Providers for the app data values
60
+     */
61
+    public static function appDataProvider(): array {
62
+        return [
63
+            [
64
+                ['description' => " \t  This is a multiline \n test with \n \t \n \n some new lines   "],
65
+                ['description' => "This is a multiline \n test with \n \t \n \n some new lines"],
66
+            ],
67
+            [
68
+                ['description' => " \t  This is a multiline \n test with \n \t   some new lines   "],
69
+                ['description' => "This is a multiline \n test with \n \t   some new lines"],
70
+            ],
71
+            [
72
+                ['description' => hex2bin('5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d')],
73
+                ['description' => "Permet de s'authentifier dans piwigo directement avec ses identifiants owncloud sans les retaper et met à jours ceux ci en cas de changement de mot de passe."],
74
+            ],
75
+            [
76
+                ['not-a-description' => " \t  This is a multiline \n test with \n \t   some new lines   "],
77
+                [
78
+                    'not-a-description' => " \t  This is a multiline \n test with \n \t   some new lines   ",
79
+                    'description' => '',
80
+                ],
81
+            ],
82
+            [
83
+                ['description' => [100, 'bla']],
84
+                ['description' => ''],
85
+            ],
86
+        ];
87
+    }
88 88
 
89
-	/**
90
-	 * Test app info parser
91
-	 */
92
-	#[\PHPUnit\Framework\Attributes\DataProvider('appDataProvider')]
93
-	public function testApplyL10NNoLanguage(array $data, array $expected): void {
94
-		$parser = new InfoParser();
95
-		$this->assertSame($expected, $parser->applyL10N($data));
96
-	}
89
+    /**
90
+     * Test app info parser
91
+     */
92
+    #[\PHPUnit\Framework\Attributes\DataProvider('appDataProvider')]
93
+    public function testApplyL10NNoLanguage(array $data, array $expected): void {
94
+        $parser = new InfoParser();
95
+        $this->assertSame($expected, $parser->applyL10N($data));
96
+    }
97 97
 
98
-	public function testApplyL10N(): void {
99
-		$parser = new InfoParser();
100
-		$data = $parser->parse(\OC::$SERVERROOT . '/tests/data/app/description-multi-lang.xml');
101
-		$this->assertEquals('English', $parser->applyL10N($data, 'en')['description']);
102
-		$this->assertEquals('German', $parser->applyL10N($data, 'de')['description']);
103
-	}
98
+    public function testApplyL10N(): void {
99
+        $parser = new InfoParser();
100
+        $data = $parser->parse(\OC::$SERVERROOT . '/tests/data/app/description-multi-lang.xml');
101
+        $this->assertEquals('English', $parser->applyL10N($data, 'en')['description']);
102
+        $this->assertEquals('German', $parser->applyL10N($data, 'de')['description']);
103
+    }
104 104
 
105
-	public function testApplyL10NSingleLanguage(): void {
106
-		$parser = new InfoParser();
107
-		$data = $parser->parse(\OC::$SERVERROOT . '/tests/data/app/description-single-lang.xml');
108
-		$this->assertEquals('English', $parser->applyL10N($data, 'en')['description']);
109
-	}
105
+    public function testApplyL10NSingleLanguage(): void {
106
+        $parser = new InfoParser();
107
+        $data = $parser->parse(\OC::$SERVERROOT . '/tests/data/app/description-single-lang.xml');
108
+        $this->assertEquals('English', $parser->applyL10N($data, 'en')['description']);
109
+    }
110 110
 }
Please login to merge, or discard this patch.
tests/lib/App/CompareVersionTest.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -14,65 +14,65 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class CompareVersionTest extends TestCase {
17
-	private CompareVersion $compare;
17
+    private CompareVersion $compare;
18 18
 
19
-	protected function setUp(): void {
20
-		parent::setUp();
19
+    protected function setUp(): void {
20
+        parent::setUp();
21 21
 
22
-		$this->compare = new CompareVersion();
23
-	}
22
+        $this->compare = new CompareVersion();
23
+    }
24 24
 
25
-	public static function comparisonData(): array {
26
-		return [
27
-			// Compatible versions
28
-			['13.0.0.3', '13.0.0', '>=', true],
29
-			['13.0.0.3', '13.0.0', '<=', true],
30
-			['13.0.0', '13.0.0', '>=', true],
31
-			['13.0.0', '13.0', '<=', true],
32
-			['13.0.0', '13', '>=', true],
33
-			['13.0.1', '13', '>=', true],
34
-			['13.0.1', '13', '<=', true],
35
-			['13.0.1.9', '13', '<=', true],
36
-			['13.0.1-beta.1', '13', '<=', true],
37
-			['7.4.14', '7.4', '<=', true],
38
-			['7.4.14-ubuntu', '7.4', '<=', true],
39
-			['7.4.14-ubuntu', '7.4.15', '<=', true],
40
-			['7.4.16-ubuntu', '7.4.15', '<=', false],
41
-			// Incompatible major versions
42
-			['13.0.0.3', '13.0.0', '<', false],
43
-			['12.0.0', '13.0.0', '>=', false],
44
-			['12.0.0', '13.0', '>=', false],
45
-			['12.0.0', '13', '>=', false],
46
-			['7.4.15-ubuntu', '7.4.15', '>=', true],
47
-			// Incompatible minor and patch versions
48
-			['13.0.0', '13.0.1', '>=', false],
49
-			['13.0.0', '13.1', '>=', false],
50
-			// Compatible minor and patch versions
51
-			['13.0.1', '13.0.0', '>=', true],
52
-			['13.2.0', '13.1', '>=', true],
53
-		];
54
-	}
25
+    public static function comparisonData(): array {
26
+        return [
27
+            // Compatible versions
28
+            ['13.0.0.3', '13.0.0', '>=', true],
29
+            ['13.0.0.3', '13.0.0', '<=', true],
30
+            ['13.0.0', '13.0.0', '>=', true],
31
+            ['13.0.0', '13.0', '<=', true],
32
+            ['13.0.0', '13', '>=', true],
33
+            ['13.0.1', '13', '>=', true],
34
+            ['13.0.1', '13', '<=', true],
35
+            ['13.0.1.9', '13', '<=', true],
36
+            ['13.0.1-beta.1', '13', '<=', true],
37
+            ['7.4.14', '7.4', '<=', true],
38
+            ['7.4.14-ubuntu', '7.4', '<=', true],
39
+            ['7.4.14-ubuntu', '7.4.15', '<=', true],
40
+            ['7.4.16-ubuntu', '7.4.15', '<=', false],
41
+            // Incompatible major versions
42
+            ['13.0.0.3', '13.0.0', '<', false],
43
+            ['12.0.0', '13.0.0', '>=', false],
44
+            ['12.0.0', '13.0', '>=', false],
45
+            ['12.0.0', '13', '>=', false],
46
+            ['7.4.15-ubuntu', '7.4.15', '>=', true],
47
+            // Incompatible minor and patch versions
48
+            ['13.0.0', '13.0.1', '>=', false],
49
+            ['13.0.0', '13.1', '>=', false],
50
+            // Compatible minor and patch versions
51
+            ['13.0.1', '13.0.0', '>=', true],
52
+            ['13.2.0', '13.1', '>=', true],
53
+        ];
54
+    }
55 55
 
56
-	#[\PHPUnit\Framework\Attributes\DataProvider('comparisonData')]
57
-	public function testComparison(string $actualVersion, string $requiredVersion,
58
-		string $comparator, bool $expected): void {
59
-		$isCompatible = $this->compare->isCompatible($actualVersion, $requiredVersion,
60
-			$comparator);
56
+    #[\PHPUnit\Framework\Attributes\DataProvider('comparisonData')]
57
+    public function testComparison(string $actualVersion, string $requiredVersion,
58
+        string $comparator, bool $expected): void {
59
+        $isCompatible = $this->compare->isCompatible($actualVersion, $requiredVersion,
60
+            $comparator);
61 61
 
62
-		$this->assertEquals($expected, $isCompatible);
63
-	}
62
+        $this->assertEquals($expected, $isCompatible);
63
+    }
64 64
 
65
-	public function testInvalidServerVersion(): void {
66
-		$actualVersion = '13';
67
-		$this->expectException(InvalidArgumentException::class);
65
+    public function testInvalidServerVersion(): void {
66
+        $actualVersion = '13';
67
+        $this->expectException(InvalidArgumentException::class);
68 68
 
69
-		$this->compare->isCompatible($actualVersion, '13.0.0');
70
-	}
69
+        $this->compare->isCompatible($actualVersion, '13.0.0');
70
+    }
71 71
 
72
-	public function testInvalidRequiredVersion(): void {
73
-		$actualVersion = '13.0.0';
74
-		$this->expectException(InvalidArgumentException::class);
72
+    public function testInvalidRequiredVersion(): void {
73
+        $actualVersion = '13.0.0';
74
+        $this->expectException(InvalidArgumentException::class);
75 75
 
76
-		$this->compare->isCompatible($actualVersion, '13.0.0.9');
77
-	}
76
+        $this->compare->isCompatible($actualVersion, '13.0.0.9');
77
+    }
78 78
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Version/VersionParserTest.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -14,73 +14,73 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class VersionParserTest extends TestCase {
17
-	private VersionParser $versionParser;
17
+    private VersionParser $versionParser;
18 18
 
19
-	protected function setUp(): void {
20
-		parent::setUp();
21
-		$this->versionParser = new VersionParser();
22
-	}
19
+    protected function setUp(): void {
20
+        parent::setUp();
21
+        $this->versionParser = new VersionParser();
22
+    }
23 23
 
24
-	/**
25
-	 * @return array
26
-	 */
27
-	public static function versionProvider(): array {
28
-		return [
29
-			[
30
-				'*',
31
-				new Version('', ''),
32
-			],
33
-			[
34
-				'<=8.1.2',
35
-				new Version('', '8.1.2'),
36
-			],
37
-			[
38
-				'<=9',
39
-				new Version('', '9'),
40
-			],
41
-			[
42
-				'>=9.3.2',
43
-				new Version('9.3.2', ''),
44
-			],
45
-			[
46
-				'>=8.1.2 <=9.3.2',
47
-				new Version('8.1.2', '9.3.2'),
48
-			],
49
-			[
50
-				'>=8.2 <=9.1',
51
-				new Version('8.2', '9.1'),
52
-			],
53
-			[
54
-				'>=9 <=11',
55
-				new Version('9', '11'),
56
-			],
57
-		];
58
-	}
24
+    /**
25
+     * @return array
26
+     */
27
+    public static function versionProvider(): array {
28
+        return [
29
+            [
30
+                '*',
31
+                new Version('', ''),
32
+            ],
33
+            [
34
+                '<=8.1.2',
35
+                new Version('', '8.1.2'),
36
+            ],
37
+            [
38
+                '<=9',
39
+                new Version('', '9'),
40
+            ],
41
+            [
42
+                '>=9.3.2',
43
+                new Version('9.3.2', ''),
44
+            ],
45
+            [
46
+                '>=8.1.2 <=9.3.2',
47
+                new Version('8.1.2', '9.3.2'),
48
+            ],
49
+            [
50
+                '>=8.2 <=9.1',
51
+                new Version('8.2', '9.1'),
52
+            ],
53
+            [
54
+                '>=9 <=11',
55
+                new Version('9', '11'),
56
+            ],
57
+        ];
58
+    }
59 59
 
60
-	/**
61
-	 *
62
-	 * @param string $input
63
-	 * @param Version $expected
64
-	 */
65
-	#[\PHPUnit\Framework\Attributes\DataProvider('versionProvider')]
66
-	public function testGetVersion($input,
67
-		Version $expected): void {
68
-		$this->assertEquals($expected, $this->versionParser->getVersion($input));
69
-	}
60
+    /**
61
+     *
62
+     * @param string $input
63
+     * @param Version $expected
64
+     */
65
+    #[\PHPUnit\Framework\Attributes\DataProvider('versionProvider')]
66
+    public function testGetVersion($input,
67
+        Version $expected): void {
68
+        $this->assertEquals($expected, $this->versionParser->getVersion($input));
69
+    }
70 70
 
71 71
 
72
-	public function testGetVersionException(): void {
73
-		$this->expectException(\Exception::class);
74
-		$this->expectExceptionMessage('Version cannot be parsed: BogusVersion');
72
+    public function testGetVersionException(): void {
73
+        $this->expectException(\Exception::class);
74
+        $this->expectExceptionMessage('Version cannot be parsed: BogusVersion');
75 75
 
76
-		$this->versionParser->getVersion('BogusVersion');
77
-	}
76
+        $this->versionParser->getVersion('BogusVersion');
77
+    }
78 78
 
79 79
 
80
-	public function testGetVersionExceptionWithMultiple(): void {
81
-		$this->expectException(\Exception::class);
82
-		$this->expectExceptionMessage('Version cannot be parsed: >=8.2 <=9.1a');
80
+    public function testGetVersionExceptionWithMultiple(): void {
81
+        $this->expectException(\Exception::class);
82
+        $this->expectExceptionMessage('Version cannot be parsed: >=8.2 <=9.1a');
83 83
 
84
-		$this->versionParser->getVersion('>=8.2 <=9.1a');
85
-	}
84
+        $this->versionParser->getVersion('>=8.2 <=9.1a');
85
+    }
86 86
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/BundleFetcherTest.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -21,41 +21,41 @@
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class BundleFetcherTest extends TestCase {
24
-	private IL10N&MockObject $l10n;
25
-	private BundleFetcher $bundleFetcher;
26
-
27
-	protected function setUp(): void {
28
-		parent::setUp();
29
-
30
-		$this->l10n = $this->createMock(IL10N::class);
31
-
32
-		$this->bundleFetcher = new BundleFetcher(
33
-			$this->l10n
34
-		);
35
-	}
36
-
37
-	public function testGetBundles(): void {
38
-		$expected = [
39
-			new EnterpriseBundle($this->l10n),
40
-			new HubBundle($this->l10n),
41
-			new GroupwareBundle($this->l10n),
42
-			new SocialSharingBundle($this->l10n),
43
-			new EducationBundle($this->l10n),
44
-			new PublicSectorBundle($this->l10n),
45
-		];
46
-		$this->assertEquals($expected, $this->bundleFetcher->getBundles());
47
-	}
48
-
49
-	public function testGetBundleByIdentifier(): void {
50
-		$this->assertEquals(new EnterpriseBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('EnterpriseBundle'));
51
-		$this->assertEquals(new GroupwareBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('GroupwareBundle'));
52
-	}
53
-
54
-
55
-	public function testGetBundleByIdentifierWithException(): void {
56
-		$this->expectException(\BadMethodCallException::class);
57
-		$this->expectExceptionMessage('Bundle with specified identifier does not exist');
58
-
59
-		$this->bundleFetcher->getBundleByIdentifier('NotExistingBundle');
60
-	}
24
+    private IL10N&MockObject $l10n;
25
+    private BundleFetcher $bundleFetcher;
26
+
27
+    protected function setUp(): void {
28
+        parent::setUp();
29
+
30
+        $this->l10n = $this->createMock(IL10N::class);
31
+
32
+        $this->bundleFetcher = new BundleFetcher(
33
+            $this->l10n
34
+        );
35
+    }
36
+
37
+    public function testGetBundles(): void {
38
+        $expected = [
39
+            new EnterpriseBundle($this->l10n),
40
+            new HubBundle($this->l10n),
41
+            new GroupwareBundle($this->l10n),
42
+            new SocialSharingBundle($this->l10n),
43
+            new EducationBundle($this->l10n),
44
+            new PublicSectorBundle($this->l10n),
45
+        ];
46
+        $this->assertEquals($expected, $this->bundleFetcher->getBundles());
47
+    }
48
+
49
+    public function testGetBundleByIdentifier(): void {
50
+        $this->assertEquals(new EnterpriseBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('EnterpriseBundle'));
51
+        $this->assertEquals(new GroupwareBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('GroupwareBundle'));
52
+    }
53
+
54
+
55
+    public function testGetBundleByIdentifierWithException(): void {
56
+        $this->expectException(\BadMethodCallException::class);
57
+        $this->expectExceptionMessage('Bundle with specified identifier does not exist');
58
+
59
+        $this->bundleFetcher->getBundleByIdentifier('NotExistingBundle');
60
+    }
61 61
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/BundleBase.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 abstract class BundleBase extends TestCase {
18
-	protected IL10N&MockObject $l10n;
19
-	protected Bundle $bundle;
20
-	protected string $bundleIdentifier;
21
-	protected string $bundleName;
22
-	protected array $bundleAppIds;
23
-
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-		$this->l10n = $this->createMock(IL10N::class);
27
-		$this->l10n->method('t')
28
-			->willReturnCallback(function ($text, $parameters = []) {
29
-				return vsprintf($text, $parameters);
30
-			});
31
-	}
32
-
33
-	public function testGetIdentifier(): void {
34
-		$this->assertSame($this->bundleIdentifier, $this->bundle->getIdentifier());
35
-	}
36
-
37
-	public function testGetName(): void {
38
-		$this->assertSame($this->bundleName, $this->bundle->getName());
39
-	}
40
-
41
-	public function testGetAppIdentifiers(): void {
42
-		$this->assertSame($this->bundleAppIds, $this->bundle->getAppIdentifiers());
43
-	}
18
+    protected IL10N&MockObject $l10n;
19
+    protected Bundle $bundle;
20
+    protected string $bundleIdentifier;
21
+    protected string $bundleName;
22
+    protected array $bundleAppIds;
23
+
24
+    protected function setUp(): void {
25
+        parent::setUp();
26
+        $this->l10n = $this->createMock(IL10N::class);
27
+        $this->l10n->method('t')
28
+            ->willReturnCallback(function ($text, $parameters = []) {
29
+                return vsprintf($text, $parameters);
30
+            });
31
+    }
32
+
33
+    public function testGetIdentifier(): void {
34
+        $this->assertSame($this->bundleIdentifier, $this->bundle->getIdentifier());
35
+    }
36
+
37
+    public function testGetName(): void {
38
+        $this->assertSame($this->bundleName, $this->bundle->getName());
39
+    }
40
+
41
+    public function testGetAppIdentifiers(): void {
42
+        $this->assertSame($this->bundleAppIds, $this->bundle->getAppIdentifiers());
43
+    }
44 44
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Fetcher/FetcherBase.php 1 patch
Indentation   +656 added lines, -656 removed lines patch added patch discarded remove patch
@@ -27,660 +27,660 @@
 block discarded – undo
27 27
 use Test\TestCase;
28 28
 
29 29
 abstract class FetcherBase extends TestCase {
30
-	protected Factory&MockObject $appDataFactory;
31
-	protected IAppData&MockObject $appData;
32
-	protected IClientService&MockObject $clientService;
33
-	protected ITimeFactory&MockObject $timeFactory;
34
-	protected IConfig&MockObject $config;
35
-	protected LoggerInterface&MockObject $logger;
36
-	protected IRegistry&MockObject $registry;
37
-	protected Fetcher $fetcher;
38
-	protected string $fileName;
39
-	protected string $endpoint;
40
-
41
-	protected function setUp(): void {
42
-		parent::setUp();
43
-		$this->appDataFactory = $this->createMock(Factory::class);
44
-		$this->appData = $this->createMock(AppData::class);
45
-		$this->appDataFactory->expects($this->once())
46
-			->method('get')
47
-			->with('appstore')
48
-			->willReturn($this->appData);
49
-		$this->clientService = $this->createMock(IClientService::class);
50
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
51
-		$this->config = $this->createMock(IConfig::class);
52
-		$this->logger = $this->createMock(LoggerInterface::class);
53
-		$this->registry = $this->createMock(IRegistry::class);
54
-	}
55
-
56
-	public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion(): void {
57
-		$this->config
58
-			->method('getSystemValueString')
59
-			->willReturnCallback(function ($var, $default) {
60
-				if ($var === 'version') {
61
-					return '11.0.0.2';
62
-				}
63
-				return $default;
64
-			});
65
-		$this->config->method('getSystemValueBool')
66
-			->willReturnArgument(1);
67
-
68
-		$folder = $this->createMock(ISimpleFolder::class);
69
-		$file = $this->createMock(ISimpleFile::class);
70
-		$this->appData
71
-			->expects($this->once())
72
-			->method('getFolder')
73
-			->with('/')
74
-			->willReturn($folder);
75
-		$folder
76
-			->expects($this->once())
77
-			->method('getFile')
78
-			->with($this->fileName)
79
-			->willReturn($file);
80
-		$file
81
-			->expects($this->once())
82
-			->method('getContent')
83
-			->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}],"ncversion":"11.0.0.2"}');
84
-		$this->timeFactory
85
-			->expects($this->once())
86
-			->method('getTime')
87
-			->willReturn(1499);
88
-
89
-		$expected = [
90
-			[
91
-				'id' => 'MyApp',
92
-			],
93
-		];
94
-		$this->assertSame($expected, $this->fetcher->get());
95
-	}
96
-
97
-	public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion(): void {
98
-		$this->config
99
-			->method('getSystemValueString')
100
-			->willReturnCallback(function ($var, $default) {
101
-				if ($var === 'appstoreurl') {
102
-					return 'https://apps.nextcloud.com/api/v1';
103
-				} elseif ($var === 'version') {
104
-					return '11.0.0.2';
105
-				}
106
-				return $default;
107
-			});
108
-		$this->config->method('getSystemValueBool')
109
-			->willReturnArgument(1);
110
-
111
-		$folder = $this->createMock(ISimpleFolder::class);
112
-		$file = $this->createMock(ISimpleFile::class);
113
-		$this->appData
114
-			->expects($this->once())
115
-			->method('getFolder')
116
-			->with('/')
117
-			->willReturn($folder);
118
-		$folder
119
-			->expects($this->once())
120
-			->method('getFile')
121
-			->with($this->fileName)
122
-			->willThrowException(new NotFoundException());
123
-		$folder
124
-			->expects($this->once())
125
-			->method('newFile')
126
-			->with($this->fileName)
127
-			->willReturn($file);
128
-		$client = $this->createMock(IClient::class);
129
-		$this->clientService
130
-			->expects($this->once())
131
-			->method('newClient')
132
-			->willReturn($client);
133
-		$response = $this->createMock(IResponse::class);
134
-		$client
135
-			->expects($this->once())
136
-			->method('get')
137
-			->with($this->endpoint)
138
-			->willReturn($response);
139
-		$response
140
-			->expects($this->once())
141
-			->method('getBody')
142
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
143
-		$response->method('getHeader')
144
-			->with($this->equalTo('ETag'))
145
-			->willReturn('"myETag"');
146
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
147
-		$file
148
-			->expects($this->once())
149
-			->method('putContent')
150
-			->with($fileData);
151
-		$file
152
-			->expects($this->once())
153
-			->method('getContent')
154
-			->willReturn($fileData);
155
-		$this->timeFactory
156
-			->expects($this->once())
157
-			->method('getTime')
158
-			->willReturn(1502);
159
-
160
-		$expected = [
161
-			[
162
-				'id' => 'MyNewApp',
163
-				'foo' => 'foo',
164
-			],
165
-			[
166
-				'id' => 'bar',
167
-			],
168
-		];
169
-		$this->assertSame($expected, $this->fetcher->get());
170
-	}
171
-
172
-	public function testGetWithAlreadyExistingFileAndOutdatedTimestamp(): void {
173
-		$this->config->method('getSystemValueString')
174
-			->willReturnCallback(function ($key, $default) {
175
-				if ($key === 'version') {
176
-					return '11.0.0.2';
177
-				} else {
178
-					return $default;
179
-				}
180
-			});
181
-		$this->config->method('getSystemValueBool')
182
-			->willReturnArgument(1);
183
-
184
-		$folder = $this->createMock(ISimpleFolder::class);
185
-		$file = $this->createMock(ISimpleFile::class);
186
-		$this->appData
187
-			->expects($this->once())
188
-			->method('getFolder')
189
-			->with('/')
190
-			->willReturn($folder);
191
-		$folder
192
-			->expects($this->once())
193
-			->method('getFile')
194
-			->with($this->fileName)
195
-			->willReturn($file);
196
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
197
-		$file
198
-			->expects($this->once())
199
-			->method('putContent')
200
-			->with($fileData);
201
-		$file
202
-			->expects($this->exactly(2))
203
-			->method('getContent')
204
-			->willReturnOnConsecutiveCalls(
205
-				'{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}',
206
-				$fileData
207
-			);
208
-		$this->timeFactory
209
-			->expects($this->exactly(2))
210
-			->method('getTime')
211
-			->willReturnOnConsecutiveCalls(
212
-				4801,
213
-				1502
214
-			);
215
-		$client = $this->createMock(IClient::class);
216
-		$this->clientService
217
-			->expects($this->once())
218
-			->method('newClient')
219
-			->willReturn($client);
220
-		$response = $this->createMock(IResponse::class);
221
-		$client
222
-			->expects($this->once())
223
-			->method('get')
224
-			->with($this->endpoint)
225
-			->willReturn($response);
226
-		$response
227
-			->expects($this->once())
228
-			->method('getBody')
229
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
230
-		$response->method('getHeader')
231
-			->with($this->equalTo('ETag'))
232
-			->willReturn('"myETag"');
233
-
234
-		$expected = [
235
-			[
236
-				'id' => 'MyNewApp',
237
-				'foo' => 'foo',
238
-			],
239
-			[
240
-				'id' => 'bar',
241
-			],
242
-		];
243
-		$this->assertSame($expected, $this->fetcher->get());
244
-	}
245
-
246
-	public function testGetWithAlreadyExistingFileAndNoVersion(): void {
247
-		$this->config
248
-			->method('getSystemValueString')
249
-			->willReturnCallback(function ($var, $default) {
250
-				if ($var === 'appstoreurl') {
251
-					return 'https://apps.nextcloud.com/api/v1';
252
-				} elseif ($var === 'version') {
253
-					return '11.0.0.2';
254
-				}
255
-				return $default;
256
-			});
257
-		$this->config->method('getSystemValueBool')
258
-			->willReturnArgument(1);
259
-
260
-		$folder = $this->createMock(ISimpleFolder::class);
261
-		$file = $this->createMock(ISimpleFile::class);
262
-		$this->appData
263
-			->expects($this->once())
264
-			->method('getFolder')
265
-			->with('/')
266
-			->willReturn($folder);
267
-		$folder
268
-			->expects($this->once())
269
-			->method('getFile')
270
-			->with($this->fileName)
271
-			->willReturn($file);
272
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
273
-		$file
274
-			->expects($this->once())
275
-			->method('putContent')
276
-			->with($fileData);
277
-		$file
278
-			->expects($this->exactly(2))
279
-			->method('getContent')
280
-			->willReturnOnConsecutiveCalls(
281
-				'{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}',
282
-				$fileData
283
-			);
284
-		$this->timeFactory
285
-			->expects($this->once())
286
-			->method('getTime')
287
-			->willReturn(1201);
288
-		$client = $this->createMock(IClient::class);
289
-		$this->clientService
290
-			->expects($this->once())
291
-			->method('newClient')
292
-			->willReturn($client);
293
-		$response = $this->createMock(IResponse::class);
294
-		$client
295
-			->expects($this->once())
296
-			->method('get')
297
-			->with($this->endpoint)
298
-			->willReturn($response);
299
-		$response
300
-			->expects($this->once())
301
-			->method('getBody')
302
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
303
-		$response->method('getHeader')
304
-			->with($this->equalTo('ETag'))
305
-			->willReturn('"myETag"');
306
-
307
-		$expected = [
308
-			[
309
-				'id' => 'MyNewApp',
310
-				'foo' => 'foo',
311
-			],
312
-			[
313
-				'id' => 'bar',
314
-			],
315
-		];
316
-		$this->assertSame($expected, $this->fetcher->get());
317
-	}
318
-
319
-	public function testGetWithAlreadyExistingFileAndOutdatedVersion(): void {
320
-		$this->config
321
-			->method('getSystemValueString')
322
-			->willReturnCallback(function ($var, $default) {
323
-				if ($var === 'appstoreurl') {
324
-					return 'https://apps.nextcloud.com/api/v1';
325
-				} elseif ($var === 'version') {
326
-					return '11.0.0.2';
327
-				}
328
-				return $default;
329
-			});
330
-		$this->config->method('getSystemValueBool')
331
-			->willReturnArgument(1);
332
-
333
-		$folder = $this->createMock(ISimpleFolder::class);
334
-		$file = $this->createMock(ISimpleFile::class);
335
-		$this->appData
336
-			->expects($this->once())
337
-			->method('getFolder')
338
-			->with('/')
339
-			->willReturn($folder);
340
-		$folder
341
-			->expects($this->once())
342
-			->method('getFile')
343
-			->with($this->fileName)
344
-			->willReturn($file);
345
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
346
-		$file
347
-			->expects($this->once())
348
-			->method('putContent')
349
-			->with($fileData);
350
-		$file
351
-			->expects($this->exactly(2))
352
-			->method('getContent')
353
-			->willReturnOnConsecutiveCalls(
354
-				'{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"',
355
-				$fileData
356
-			);
357
-		$this->timeFactory
358
-			->method('getTime')
359
-			->willReturn(1201);
360
-		$client = $this->createMock(IClient::class);
361
-		$this->clientService
362
-			->expects($this->once())
363
-			->method('newClient')
364
-			->willReturn($client);
365
-		$response = $this->createMock(IResponse::class);
366
-		$client
367
-			->expects($this->once())
368
-			->method('get')
369
-			->with($this->endpoint)
370
-			->willReturn($response);
371
-		$response
372
-			->expects($this->once())
373
-			->method('getBody')
374
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
375
-		$response->method('getHeader')
376
-			->with($this->equalTo('ETag'))
377
-			->willReturn('"myETag"');
378
-
379
-		$expected = [
380
-			[
381
-				'id' => 'MyNewApp',
382
-				'foo' => 'foo',
383
-			],
384
-			[
385
-				'id' => 'bar',
386
-			],
387
-		];
388
-		$this->assertSame($expected, $this->fetcher->get());
389
-	}
390
-
391
-	public function testGetWithExceptionInClient(): void {
392
-		$this->config->method('getSystemValueString')
393
-			->willReturnArgument(1);
394
-		$this->config->method('getSystemValueBool')
395
-			->willReturnArgument(1);
396
-
397
-		$folder = $this->createMock(ISimpleFolder::class);
398
-		$file = $this->createMock(ISimpleFile::class);
399
-		$this->appData
400
-			->expects($this->once())
401
-			->method('getFolder')
402
-			->with('/')
403
-			->willReturn($folder);
404
-		$folder
405
-			->expects($this->once())
406
-			->method('getFile')
407
-			->with($this->fileName)
408
-			->willReturn($file);
409
-		$file
410
-			->expects($this->once())
411
-			->method('getContent')
412
-			->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
413
-		$client = $this->createMock(IClient::class);
414
-		$this->clientService
415
-			->expects($this->once())
416
-			->method('newClient')
417
-			->willReturn($client);
418
-		$client
419
-			->expects($this->once())
420
-			->method('get')
421
-			->with($this->endpoint)
422
-			->willThrowException(new \Exception());
423
-
424
-		$this->assertSame([], $this->fetcher->get());
425
-	}
426
-
427
-	public function testGetMatchingETag(): void {
428
-		$this->config->method('getSystemValueString')
429
-			->willReturnCallback(function ($key, $default) {
430
-				if ($key === 'version') {
431
-					return '11.0.0.2';
432
-				} else {
433
-					return $default;
434
-				}
435
-			});
436
-		$this->config->method('getSystemValueBool')
437
-			->willReturnArgument(1);
438
-
439
-		$this->config->method('getAppValue')
440
-			->willReturnMap([
441
-				['settings', 'appstore-fetcher-lastFailure', '0', '0'],
442
-				['settings', 'appstore-timeout', '120', '120'],
443
-			]);
444
-
445
-		$folder = $this->createMock(ISimpleFolder::class);
446
-		$file = $this->createMock(ISimpleFile::class);
447
-		$this->appData
448
-			->expects($this->once())
449
-			->method('getFolder')
450
-			->with('/')
451
-			->willReturn($folder);
452
-		$folder
453
-			->expects($this->once())
454
-			->method('getFile')
455
-			->with($this->fileName)
456
-			->willReturn($file);
457
-		$origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
458
-
459
-		$newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
460
-		$file
461
-			->expects($this->once())
462
-			->method('putContent')
463
-			->with($newData);
464
-		$file
465
-			->expects($this->exactly(2))
466
-			->method('getContent')
467
-			->willReturnOnConsecutiveCalls(
468
-				$origData,
469
-				$newData,
470
-			);
471
-		$this->timeFactory
472
-			->expects($this->exactly(2))
473
-			->method('getTime')
474
-			->willReturnOnConsecutiveCalls(
475
-				4801,
476
-				4802
477
-			);
478
-		$client = $this->createMock(IClient::class);
479
-		$this->clientService
480
-			->expects($this->once())
481
-			->method('newClient')
482
-			->willReturn($client);
483
-		$response = $this->createMock(IResponse::class);
484
-		$client
485
-			->expects($this->once())
486
-			->method('get')
487
-			->with(
488
-				$this->equalTo($this->endpoint),
489
-				$this->equalTo([
490
-					'timeout' => 120,
491
-					'headers' => [
492
-						'If-None-Match' => '"myETag"'
493
-					]
494
-				])
495
-			)->willReturn($response);
496
-		$response->method('getStatusCode')
497
-			->willReturn(304);
498
-
499
-		$expected = [
500
-			[
501
-				'id' => 'MyNewApp',
502
-				'foo' => 'foo',
503
-			],
504
-			[
505
-				'id' => 'bar',
506
-			],
507
-		];
508
-
509
-		$this->assertSame($expected, $this->fetcher->get());
510
-	}
511
-
512
-	public function testGetNoMatchingETag(): void {
513
-		$this->config->method('getSystemValueString')
514
-			->willReturnCallback(function ($key, $default) {
515
-				if ($key === 'version') {
516
-					return '11.0.0.2';
517
-				} else {
518
-					return $default;
519
-				}
520
-			});
521
-		$this->config->method('getSystemValueBool')
522
-			->willReturnArgument(1);
523
-
524
-		$this->config->method('getAppValue')
525
-			->willReturnMap([
526
-				['settings', 'appstore-fetcher-lastFailure', '0', '0'],
527
-				['settings', 'appstore-timeout', '120', '120'],
528
-			]);
529
-
530
-		$folder = $this->createMock(ISimpleFolder::class);
531
-		$file = $this->createMock(ISimpleFile::class);
532
-		$this->appData
533
-			->expects($this->once())
534
-			->method('getFolder')
535
-			->with('/')
536
-			->willReturn($folder);
537
-		$folder
538
-			->expects($this->once())
539
-			->method('getFile')
540
-			->with($this->fileName)
541
-			->willReturn($file);
542
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}';
543
-		$file
544
-			->expects($this->once())
545
-			->method('putContent')
546
-			->with($fileData);
547
-		$file
548
-			->expects($this->exactly(2))
549
-			->method('getContent')
550
-			->willReturnOnConsecutiveCalls(
551
-				'{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
552
-				$fileData,
553
-			);
554
-		$this->timeFactory
555
-			->expects($this->exactly(2))
556
-			->method('getTime')
557
-			->willReturnOnConsecutiveCalls(
558
-				4801,
559
-				4802,
560
-			);
561
-		$client = $this->createMock(IClient::class);
562
-		$this->clientService
563
-			->expects($this->once())
564
-			->method('newClient')
565
-			->willReturn($client);
566
-		$response = $this->createMock(IResponse::class);
567
-		$client
568
-			->expects($this->once())
569
-			->method('get')
570
-			->with(
571
-				$this->equalTo($this->endpoint),
572
-				$this->equalTo([
573
-					'timeout' => 120,
574
-					'headers' => [
575
-						'If-None-Match' => '"myETag"',
576
-					]
577
-				])
578
-			)
579
-			->willReturn($response);
580
-		$response->method('getStatusCode')
581
-			->willReturn(200);
582
-		$response
583
-			->expects($this->once())
584
-			->method('getBody')
585
-			->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
586
-		$response->method('getHeader')
587
-			->with($this->equalTo('ETag'))
588
-			->willReturn('"newETag"');
589
-
590
-		$expected = [
591
-			[
592
-				'id' => 'MyNewApp',
593
-				'foo' => 'foo',
594
-			],
595
-			[
596
-				'id' => 'bar',
597
-			],
598
-		];
599
-		$this->assertSame($expected, $this->fetcher->get());
600
-	}
601
-
602
-
603
-	public function testFetchAfterUpgradeNoETag(): void {
604
-		$this->config->method('getSystemValueString')
605
-			->willReturnCallback(function ($key, $default) {
606
-				if ($key === 'version') {
607
-					return '11.0.0.3';
608
-				} else {
609
-					return $default;
610
-				}
611
-			});
612
-		$this->config->method('getSystemValueBool')
613
-			->willReturnArgument(1);
614
-
615
-		$this->config->method('getAppValue')
616
-			->willReturnMap([
617
-				['settings', 'appstore-fetcher-lastFailure', '0', '0'],
618
-				['settings', 'appstore-timeout', '120', '120'],
619
-			]);
620
-
621
-		$folder = $this->createMock(ISimpleFolder::class);
622
-		$file = $this->createMock(ISimpleFile::class);
623
-		$this->appData
624
-			->expects($this->once())
625
-			->method('getFolder')
626
-			->with('/')
627
-			->willReturn($folder);
628
-		$folder
629
-			->expects($this->once())
630
-			->method('getFile')
631
-			->with($this->fileName)
632
-			->willReturn($file);
633
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}';
634
-		$file
635
-			->expects($this->once())
636
-			->method('putContent')
637
-			->with($fileData);
638
-		$file
639
-			->expects($this->exactly(2))
640
-			->method('getContent')
641
-			->willReturnOnConsecutiveCalls(
642
-				'{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
643
-				$fileData
644
-			);
645
-		$client = $this->createMock(IClient::class);
646
-		$this->clientService
647
-			->expects($this->once())
648
-			->method('newClient')
649
-			->willReturn($client);
650
-		$response = $this->createMock(IResponse::class);
651
-		$client
652
-			->expects($this->once())
653
-			->method('get')
654
-			->with(
655
-				$this->equalTo($this->endpoint),
656
-				$this->equalTo([
657
-					'timeout' => 120,
658
-				])
659
-			)
660
-			->willReturn($response);
661
-		$response->method('getStatusCode')
662
-			->willReturn(200);
663
-		$response
664
-			->expects($this->once())
665
-			->method('getBody')
666
-			->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
667
-		$response->method('getHeader')
668
-			->with($this->equalTo('ETag'))
669
-			->willReturn('"newETag"');
670
-		$this->timeFactory
671
-			->expects($this->once())
672
-			->method('getTime')
673
-			->willReturn(1501);
674
-
675
-		$expected = [
676
-			[
677
-				'id' => 'MyNewApp',
678
-				'foo' => 'foo',
679
-			],
680
-			[
681
-				'id' => 'bar',
682
-			],
683
-		];
684
-		$this->assertSame($expected, $this->fetcher->get());
685
-	}
30
+    protected Factory&MockObject $appDataFactory;
31
+    protected IAppData&MockObject $appData;
32
+    protected IClientService&MockObject $clientService;
33
+    protected ITimeFactory&MockObject $timeFactory;
34
+    protected IConfig&MockObject $config;
35
+    protected LoggerInterface&MockObject $logger;
36
+    protected IRegistry&MockObject $registry;
37
+    protected Fetcher $fetcher;
38
+    protected string $fileName;
39
+    protected string $endpoint;
40
+
41
+    protected function setUp(): void {
42
+        parent::setUp();
43
+        $this->appDataFactory = $this->createMock(Factory::class);
44
+        $this->appData = $this->createMock(AppData::class);
45
+        $this->appDataFactory->expects($this->once())
46
+            ->method('get')
47
+            ->with('appstore')
48
+            ->willReturn($this->appData);
49
+        $this->clientService = $this->createMock(IClientService::class);
50
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
51
+        $this->config = $this->createMock(IConfig::class);
52
+        $this->logger = $this->createMock(LoggerInterface::class);
53
+        $this->registry = $this->createMock(IRegistry::class);
54
+    }
55
+
56
+    public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion(): void {
57
+        $this->config
58
+            ->method('getSystemValueString')
59
+            ->willReturnCallback(function ($var, $default) {
60
+                if ($var === 'version') {
61
+                    return '11.0.0.2';
62
+                }
63
+                return $default;
64
+            });
65
+        $this->config->method('getSystemValueBool')
66
+            ->willReturnArgument(1);
67
+
68
+        $folder = $this->createMock(ISimpleFolder::class);
69
+        $file = $this->createMock(ISimpleFile::class);
70
+        $this->appData
71
+            ->expects($this->once())
72
+            ->method('getFolder')
73
+            ->with('/')
74
+            ->willReturn($folder);
75
+        $folder
76
+            ->expects($this->once())
77
+            ->method('getFile')
78
+            ->with($this->fileName)
79
+            ->willReturn($file);
80
+        $file
81
+            ->expects($this->once())
82
+            ->method('getContent')
83
+            ->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}],"ncversion":"11.0.0.2"}');
84
+        $this->timeFactory
85
+            ->expects($this->once())
86
+            ->method('getTime')
87
+            ->willReturn(1499);
88
+
89
+        $expected = [
90
+            [
91
+                'id' => 'MyApp',
92
+            ],
93
+        ];
94
+        $this->assertSame($expected, $this->fetcher->get());
95
+    }
96
+
97
+    public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion(): void {
98
+        $this->config
99
+            ->method('getSystemValueString')
100
+            ->willReturnCallback(function ($var, $default) {
101
+                if ($var === 'appstoreurl') {
102
+                    return 'https://apps.nextcloud.com/api/v1';
103
+                } elseif ($var === 'version') {
104
+                    return '11.0.0.2';
105
+                }
106
+                return $default;
107
+            });
108
+        $this->config->method('getSystemValueBool')
109
+            ->willReturnArgument(1);
110
+
111
+        $folder = $this->createMock(ISimpleFolder::class);
112
+        $file = $this->createMock(ISimpleFile::class);
113
+        $this->appData
114
+            ->expects($this->once())
115
+            ->method('getFolder')
116
+            ->with('/')
117
+            ->willReturn($folder);
118
+        $folder
119
+            ->expects($this->once())
120
+            ->method('getFile')
121
+            ->with($this->fileName)
122
+            ->willThrowException(new NotFoundException());
123
+        $folder
124
+            ->expects($this->once())
125
+            ->method('newFile')
126
+            ->with($this->fileName)
127
+            ->willReturn($file);
128
+        $client = $this->createMock(IClient::class);
129
+        $this->clientService
130
+            ->expects($this->once())
131
+            ->method('newClient')
132
+            ->willReturn($client);
133
+        $response = $this->createMock(IResponse::class);
134
+        $client
135
+            ->expects($this->once())
136
+            ->method('get')
137
+            ->with($this->endpoint)
138
+            ->willReturn($response);
139
+        $response
140
+            ->expects($this->once())
141
+            ->method('getBody')
142
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
143
+        $response->method('getHeader')
144
+            ->with($this->equalTo('ETag'))
145
+            ->willReturn('"myETag"');
146
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
147
+        $file
148
+            ->expects($this->once())
149
+            ->method('putContent')
150
+            ->with($fileData);
151
+        $file
152
+            ->expects($this->once())
153
+            ->method('getContent')
154
+            ->willReturn($fileData);
155
+        $this->timeFactory
156
+            ->expects($this->once())
157
+            ->method('getTime')
158
+            ->willReturn(1502);
159
+
160
+        $expected = [
161
+            [
162
+                'id' => 'MyNewApp',
163
+                'foo' => 'foo',
164
+            ],
165
+            [
166
+                'id' => 'bar',
167
+            ],
168
+        ];
169
+        $this->assertSame($expected, $this->fetcher->get());
170
+    }
171
+
172
+    public function testGetWithAlreadyExistingFileAndOutdatedTimestamp(): void {
173
+        $this->config->method('getSystemValueString')
174
+            ->willReturnCallback(function ($key, $default) {
175
+                if ($key === 'version') {
176
+                    return '11.0.0.2';
177
+                } else {
178
+                    return $default;
179
+                }
180
+            });
181
+        $this->config->method('getSystemValueBool')
182
+            ->willReturnArgument(1);
183
+
184
+        $folder = $this->createMock(ISimpleFolder::class);
185
+        $file = $this->createMock(ISimpleFile::class);
186
+        $this->appData
187
+            ->expects($this->once())
188
+            ->method('getFolder')
189
+            ->with('/')
190
+            ->willReturn($folder);
191
+        $folder
192
+            ->expects($this->once())
193
+            ->method('getFile')
194
+            ->with($this->fileName)
195
+            ->willReturn($file);
196
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
197
+        $file
198
+            ->expects($this->once())
199
+            ->method('putContent')
200
+            ->with($fileData);
201
+        $file
202
+            ->expects($this->exactly(2))
203
+            ->method('getContent')
204
+            ->willReturnOnConsecutiveCalls(
205
+                '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}',
206
+                $fileData
207
+            );
208
+        $this->timeFactory
209
+            ->expects($this->exactly(2))
210
+            ->method('getTime')
211
+            ->willReturnOnConsecutiveCalls(
212
+                4801,
213
+                1502
214
+            );
215
+        $client = $this->createMock(IClient::class);
216
+        $this->clientService
217
+            ->expects($this->once())
218
+            ->method('newClient')
219
+            ->willReturn($client);
220
+        $response = $this->createMock(IResponse::class);
221
+        $client
222
+            ->expects($this->once())
223
+            ->method('get')
224
+            ->with($this->endpoint)
225
+            ->willReturn($response);
226
+        $response
227
+            ->expects($this->once())
228
+            ->method('getBody')
229
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
230
+        $response->method('getHeader')
231
+            ->with($this->equalTo('ETag'))
232
+            ->willReturn('"myETag"');
233
+
234
+        $expected = [
235
+            [
236
+                'id' => 'MyNewApp',
237
+                'foo' => 'foo',
238
+            ],
239
+            [
240
+                'id' => 'bar',
241
+            ],
242
+        ];
243
+        $this->assertSame($expected, $this->fetcher->get());
244
+    }
245
+
246
+    public function testGetWithAlreadyExistingFileAndNoVersion(): void {
247
+        $this->config
248
+            ->method('getSystemValueString')
249
+            ->willReturnCallback(function ($var, $default) {
250
+                if ($var === 'appstoreurl') {
251
+                    return 'https://apps.nextcloud.com/api/v1';
252
+                } elseif ($var === 'version') {
253
+                    return '11.0.0.2';
254
+                }
255
+                return $default;
256
+            });
257
+        $this->config->method('getSystemValueBool')
258
+            ->willReturnArgument(1);
259
+
260
+        $folder = $this->createMock(ISimpleFolder::class);
261
+        $file = $this->createMock(ISimpleFile::class);
262
+        $this->appData
263
+            ->expects($this->once())
264
+            ->method('getFolder')
265
+            ->with('/')
266
+            ->willReturn($folder);
267
+        $folder
268
+            ->expects($this->once())
269
+            ->method('getFile')
270
+            ->with($this->fileName)
271
+            ->willReturn($file);
272
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
273
+        $file
274
+            ->expects($this->once())
275
+            ->method('putContent')
276
+            ->with($fileData);
277
+        $file
278
+            ->expects($this->exactly(2))
279
+            ->method('getContent')
280
+            ->willReturnOnConsecutiveCalls(
281
+                '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}',
282
+                $fileData
283
+            );
284
+        $this->timeFactory
285
+            ->expects($this->once())
286
+            ->method('getTime')
287
+            ->willReturn(1201);
288
+        $client = $this->createMock(IClient::class);
289
+        $this->clientService
290
+            ->expects($this->once())
291
+            ->method('newClient')
292
+            ->willReturn($client);
293
+        $response = $this->createMock(IResponse::class);
294
+        $client
295
+            ->expects($this->once())
296
+            ->method('get')
297
+            ->with($this->endpoint)
298
+            ->willReturn($response);
299
+        $response
300
+            ->expects($this->once())
301
+            ->method('getBody')
302
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
303
+        $response->method('getHeader')
304
+            ->with($this->equalTo('ETag'))
305
+            ->willReturn('"myETag"');
306
+
307
+        $expected = [
308
+            [
309
+                'id' => 'MyNewApp',
310
+                'foo' => 'foo',
311
+            ],
312
+            [
313
+                'id' => 'bar',
314
+            ],
315
+        ];
316
+        $this->assertSame($expected, $this->fetcher->get());
317
+    }
318
+
319
+    public function testGetWithAlreadyExistingFileAndOutdatedVersion(): void {
320
+        $this->config
321
+            ->method('getSystemValueString')
322
+            ->willReturnCallback(function ($var, $default) {
323
+                if ($var === 'appstoreurl') {
324
+                    return 'https://apps.nextcloud.com/api/v1';
325
+                } elseif ($var === 'version') {
326
+                    return '11.0.0.2';
327
+                }
328
+                return $default;
329
+            });
330
+        $this->config->method('getSystemValueBool')
331
+            ->willReturnArgument(1);
332
+
333
+        $folder = $this->createMock(ISimpleFolder::class);
334
+        $file = $this->createMock(ISimpleFile::class);
335
+        $this->appData
336
+            ->expects($this->once())
337
+            ->method('getFolder')
338
+            ->with('/')
339
+            ->willReturn($folder);
340
+        $folder
341
+            ->expects($this->once())
342
+            ->method('getFile')
343
+            ->with($this->fileName)
344
+            ->willReturn($file);
345
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
346
+        $file
347
+            ->expects($this->once())
348
+            ->method('putContent')
349
+            ->with($fileData);
350
+        $file
351
+            ->expects($this->exactly(2))
352
+            ->method('getContent')
353
+            ->willReturnOnConsecutiveCalls(
354
+                '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"',
355
+                $fileData
356
+            );
357
+        $this->timeFactory
358
+            ->method('getTime')
359
+            ->willReturn(1201);
360
+        $client = $this->createMock(IClient::class);
361
+        $this->clientService
362
+            ->expects($this->once())
363
+            ->method('newClient')
364
+            ->willReturn($client);
365
+        $response = $this->createMock(IResponse::class);
366
+        $client
367
+            ->expects($this->once())
368
+            ->method('get')
369
+            ->with($this->endpoint)
370
+            ->willReturn($response);
371
+        $response
372
+            ->expects($this->once())
373
+            ->method('getBody')
374
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
375
+        $response->method('getHeader')
376
+            ->with($this->equalTo('ETag'))
377
+            ->willReturn('"myETag"');
378
+
379
+        $expected = [
380
+            [
381
+                'id' => 'MyNewApp',
382
+                'foo' => 'foo',
383
+            ],
384
+            [
385
+                'id' => 'bar',
386
+            ],
387
+        ];
388
+        $this->assertSame($expected, $this->fetcher->get());
389
+    }
390
+
391
+    public function testGetWithExceptionInClient(): void {
392
+        $this->config->method('getSystemValueString')
393
+            ->willReturnArgument(1);
394
+        $this->config->method('getSystemValueBool')
395
+            ->willReturnArgument(1);
396
+
397
+        $folder = $this->createMock(ISimpleFolder::class);
398
+        $file = $this->createMock(ISimpleFile::class);
399
+        $this->appData
400
+            ->expects($this->once())
401
+            ->method('getFolder')
402
+            ->with('/')
403
+            ->willReturn($folder);
404
+        $folder
405
+            ->expects($this->once())
406
+            ->method('getFile')
407
+            ->with($this->fileName)
408
+            ->willReturn($file);
409
+        $file
410
+            ->expects($this->once())
411
+            ->method('getContent')
412
+            ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
413
+        $client = $this->createMock(IClient::class);
414
+        $this->clientService
415
+            ->expects($this->once())
416
+            ->method('newClient')
417
+            ->willReturn($client);
418
+        $client
419
+            ->expects($this->once())
420
+            ->method('get')
421
+            ->with($this->endpoint)
422
+            ->willThrowException(new \Exception());
423
+
424
+        $this->assertSame([], $this->fetcher->get());
425
+    }
426
+
427
+    public function testGetMatchingETag(): void {
428
+        $this->config->method('getSystemValueString')
429
+            ->willReturnCallback(function ($key, $default) {
430
+                if ($key === 'version') {
431
+                    return '11.0.0.2';
432
+                } else {
433
+                    return $default;
434
+                }
435
+            });
436
+        $this->config->method('getSystemValueBool')
437
+            ->willReturnArgument(1);
438
+
439
+        $this->config->method('getAppValue')
440
+            ->willReturnMap([
441
+                ['settings', 'appstore-fetcher-lastFailure', '0', '0'],
442
+                ['settings', 'appstore-timeout', '120', '120'],
443
+            ]);
444
+
445
+        $folder = $this->createMock(ISimpleFolder::class);
446
+        $file = $this->createMock(ISimpleFile::class);
447
+        $this->appData
448
+            ->expects($this->once())
449
+            ->method('getFolder')
450
+            ->with('/')
451
+            ->willReturn($folder);
452
+        $folder
453
+            ->expects($this->once())
454
+            ->method('getFile')
455
+            ->with($this->fileName)
456
+            ->willReturn($file);
457
+        $origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
458
+
459
+        $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
460
+        $file
461
+            ->expects($this->once())
462
+            ->method('putContent')
463
+            ->with($newData);
464
+        $file
465
+            ->expects($this->exactly(2))
466
+            ->method('getContent')
467
+            ->willReturnOnConsecutiveCalls(
468
+                $origData,
469
+                $newData,
470
+            );
471
+        $this->timeFactory
472
+            ->expects($this->exactly(2))
473
+            ->method('getTime')
474
+            ->willReturnOnConsecutiveCalls(
475
+                4801,
476
+                4802
477
+            );
478
+        $client = $this->createMock(IClient::class);
479
+        $this->clientService
480
+            ->expects($this->once())
481
+            ->method('newClient')
482
+            ->willReturn($client);
483
+        $response = $this->createMock(IResponse::class);
484
+        $client
485
+            ->expects($this->once())
486
+            ->method('get')
487
+            ->with(
488
+                $this->equalTo($this->endpoint),
489
+                $this->equalTo([
490
+                    'timeout' => 120,
491
+                    'headers' => [
492
+                        'If-None-Match' => '"myETag"'
493
+                    ]
494
+                ])
495
+            )->willReturn($response);
496
+        $response->method('getStatusCode')
497
+            ->willReturn(304);
498
+
499
+        $expected = [
500
+            [
501
+                'id' => 'MyNewApp',
502
+                'foo' => 'foo',
503
+            ],
504
+            [
505
+                'id' => 'bar',
506
+            ],
507
+        ];
508
+
509
+        $this->assertSame($expected, $this->fetcher->get());
510
+    }
511
+
512
+    public function testGetNoMatchingETag(): void {
513
+        $this->config->method('getSystemValueString')
514
+            ->willReturnCallback(function ($key, $default) {
515
+                if ($key === 'version') {
516
+                    return '11.0.0.2';
517
+                } else {
518
+                    return $default;
519
+                }
520
+            });
521
+        $this->config->method('getSystemValueBool')
522
+            ->willReturnArgument(1);
523
+
524
+        $this->config->method('getAppValue')
525
+            ->willReturnMap([
526
+                ['settings', 'appstore-fetcher-lastFailure', '0', '0'],
527
+                ['settings', 'appstore-timeout', '120', '120'],
528
+            ]);
529
+
530
+        $folder = $this->createMock(ISimpleFolder::class);
531
+        $file = $this->createMock(ISimpleFile::class);
532
+        $this->appData
533
+            ->expects($this->once())
534
+            ->method('getFolder')
535
+            ->with('/')
536
+            ->willReturn($folder);
537
+        $folder
538
+            ->expects($this->once())
539
+            ->method('getFile')
540
+            ->with($this->fileName)
541
+            ->willReturn($file);
542
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}';
543
+        $file
544
+            ->expects($this->once())
545
+            ->method('putContent')
546
+            ->with($fileData);
547
+        $file
548
+            ->expects($this->exactly(2))
549
+            ->method('getContent')
550
+            ->willReturnOnConsecutiveCalls(
551
+                '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
552
+                $fileData,
553
+            );
554
+        $this->timeFactory
555
+            ->expects($this->exactly(2))
556
+            ->method('getTime')
557
+            ->willReturnOnConsecutiveCalls(
558
+                4801,
559
+                4802,
560
+            );
561
+        $client = $this->createMock(IClient::class);
562
+        $this->clientService
563
+            ->expects($this->once())
564
+            ->method('newClient')
565
+            ->willReturn($client);
566
+        $response = $this->createMock(IResponse::class);
567
+        $client
568
+            ->expects($this->once())
569
+            ->method('get')
570
+            ->with(
571
+                $this->equalTo($this->endpoint),
572
+                $this->equalTo([
573
+                    'timeout' => 120,
574
+                    'headers' => [
575
+                        'If-None-Match' => '"myETag"',
576
+                    ]
577
+                ])
578
+            )
579
+            ->willReturn($response);
580
+        $response->method('getStatusCode')
581
+            ->willReturn(200);
582
+        $response
583
+            ->expects($this->once())
584
+            ->method('getBody')
585
+            ->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
586
+        $response->method('getHeader')
587
+            ->with($this->equalTo('ETag'))
588
+            ->willReturn('"newETag"');
589
+
590
+        $expected = [
591
+            [
592
+                'id' => 'MyNewApp',
593
+                'foo' => 'foo',
594
+            ],
595
+            [
596
+                'id' => 'bar',
597
+            ],
598
+        ];
599
+        $this->assertSame($expected, $this->fetcher->get());
600
+    }
601
+
602
+
603
+    public function testFetchAfterUpgradeNoETag(): void {
604
+        $this->config->method('getSystemValueString')
605
+            ->willReturnCallback(function ($key, $default) {
606
+                if ($key === 'version') {
607
+                    return '11.0.0.3';
608
+                } else {
609
+                    return $default;
610
+                }
611
+            });
612
+        $this->config->method('getSystemValueBool')
613
+            ->willReturnArgument(1);
614
+
615
+        $this->config->method('getAppValue')
616
+            ->willReturnMap([
617
+                ['settings', 'appstore-fetcher-lastFailure', '0', '0'],
618
+                ['settings', 'appstore-timeout', '120', '120'],
619
+            ]);
620
+
621
+        $folder = $this->createMock(ISimpleFolder::class);
622
+        $file = $this->createMock(ISimpleFile::class);
623
+        $this->appData
624
+            ->expects($this->once())
625
+            ->method('getFolder')
626
+            ->with('/')
627
+            ->willReturn($folder);
628
+        $folder
629
+            ->expects($this->once())
630
+            ->method('getFile')
631
+            ->with($this->fileName)
632
+            ->willReturn($file);
633
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}';
634
+        $file
635
+            ->expects($this->once())
636
+            ->method('putContent')
637
+            ->with($fileData);
638
+        $file
639
+            ->expects($this->exactly(2))
640
+            ->method('getContent')
641
+            ->willReturnOnConsecutiveCalls(
642
+                '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
643
+                $fileData
644
+            );
645
+        $client = $this->createMock(IClient::class);
646
+        $this->clientService
647
+            ->expects($this->once())
648
+            ->method('newClient')
649
+            ->willReturn($client);
650
+        $response = $this->createMock(IResponse::class);
651
+        $client
652
+            ->expects($this->once())
653
+            ->method('get')
654
+            ->with(
655
+                $this->equalTo($this->endpoint),
656
+                $this->equalTo([
657
+                    'timeout' => 120,
658
+                ])
659
+            )
660
+            ->willReturn($response);
661
+        $response->method('getStatusCode')
662
+            ->willReturn(200);
663
+        $response
664
+            ->expects($this->once())
665
+            ->method('getBody')
666
+            ->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
667
+        $response->method('getHeader')
668
+            ->with($this->equalTo('ETag'))
669
+            ->willReturn('"newETag"');
670
+        $this->timeFactory
671
+            ->expects($this->once())
672
+            ->method('getTime')
673
+            ->willReturn(1501);
674
+
675
+        $expected = [
676
+            [
677
+                'id' => 'MyNewApp',
678
+                'foo' => 'foo',
679
+            ],
680
+            [
681
+                'id' => 'bar',
682
+            ],
683
+        ];
684
+        $this->assertSame($expected, $this->fetcher->get());
685
+    }
686 686
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Fetcher/AppDiscoverFetcherTest.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -17,101 +17,101 @@
 block discarded – undo
17 17
 use PHPUnit\Framework\MockObject\MockObject;
18 18
 
19 19
 class AppDiscoverFetcherTest extends FetcherBase {
20
-	protected CompareVersion&MockObject $compareVersion;
21
-
22
-	protected function setUp(): void {
23
-		parent::setUp();
24
-		$this->fileName = 'discover.json';
25
-		$this->endpoint = 'https://apps.nextcloud.com/api/v1/discover.json';
26
-
27
-		$this->compareVersion = $this->createMock(CompareVersion::class);
28
-
29
-		$this->fetcher = new AppDiscoverFetcher(
30
-			$this->appDataFactory,
31
-			$this->clientService,
32
-			$this->timeFactory,
33
-			$this->config,
34
-			$this->logger,
35
-			$this->registry,
36
-			$this->compareVersion,
37
-		);
38
-	}
39
-
40
-	public function testAppstoreDisabled(): void {
41
-		$this->config
42
-			->method('getSystemValueBool')
43
-			->willReturnCallback(function ($var, $default) {
44
-				if ($var === 'appstoreenabled') {
45
-					return false;
46
-				}
47
-				return $default;
48
-			});
49
-		$this->appData
50
-			->expects($this->never())
51
-			->method('getFolder');
52
-
53
-		$this->assertEquals([], $this->fetcher->get());
54
-	}
55
-
56
-	public function testNoInternet(): void {
57
-		$this->config
58
-			->method('getSystemValueBool')
59
-			->willReturnCallback(function ($var, $default) {
60
-				if ($var === 'has_internet_connection') {
61
-					return false;
62
-				}
63
-				return $default;
64
-			});
65
-		$this->config
66
-			->method('getSystemValueString')
67
-			->willReturnCallback(function ($var, $default) {
68
-				return $default;
69
-			});
70
-		$this->appData
71
-			->expects($this->never())
72
-			->method('getFolder');
73
-
74
-		$this->assertEquals([], $this->fetcher->get());
75
-	}
76
-
77
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataGetETag')]
78
-	public function testGetEtag(?string $expected, bool $throws, string $content = ''): void {
79
-		$folder = $this->createMock(ISimpleFolder::class);
80
-		if (!$throws) {
81
-			$file = $this->createMock(ISimpleFile::class);
82
-			$file->expects($this->once())
83
-				->method('getContent')
84
-				->willReturn($content);
85
-			$folder->expects($this->once())
86
-				->method('getFile')
87
-				->with('discover.json')
88
-				->willReturn($file);
89
-		} else {
90
-			$folder->expects($this->once())
91
-				->method('getFile')
92
-				->with('discover.json')
93
-				->willThrowException(new NotFoundException(''));
94
-		}
95
-
96
-		$this->appData->expects($this->once())
97
-			->method('getFolder')
98
-			->with('/')
99
-			->willReturn($folder);
100
-
101
-		$etag = $this->fetcher->getETag();
102
-		$this->assertEquals($expected, $etag);
103
-		if ($expected !== null) {
104
-			$this->assertTrue(gettype($etag) === 'string');
105
-		}
106
-	}
107
-
108
-	public static function dataGetETag(): array {
109
-		return [
110
-			'file not found' => [null, true],
111
-			'empty file' => [null, false, ''],
112
-			'missing etag' => [null, false, '{ "foo": "bar" }'],
113
-			'valid etag' => ['test', false, '{ "ETag": "test" }'],
114
-			'numeric etag' => ['132', false, '{ "ETag": 132 }'],
115
-		];
116
-	}
20
+    protected CompareVersion&MockObject $compareVersion;
21
+
22
+    protected function setUp(): void {
23
+        parent::setUp();
24
+        $this->fileName = 'discover.json';
25
+        $this->endpoint = 'https://apps.nextcloud.com/api/v1/discover.json';
26
+
27
+        $this->compareVersion = $this->createMock(CompareVersion::class);
28
+
29
+        $this->fetcher = new AppDiscoverFetcher(
30
+            $this->appDataFactory,
31
+            $this->clientService,
32
+            $this->timeFactory,
33
+            $this->config,
34
+            $this->logger,
35
+            $this->registry,
36
+            $this->compareVersion,
37
+        );
38
+    }
39
+
40
+    public function testAppstoreDisabled(): void {
41
+        $this->config
42
+            ->method('getSystemValueBool')
43
+            ->willReturnCallback(function ($var, $default) {
44
+                if ($var === 'appstoreenabled') {
45
+                    return false;
46
+                }
47
+                return $default;
48
+            });
49
+        $this->appData
50
+            ->expects($this->never())
51
+            ->method('getFolder');
52
+
53
+        $this->assertEquals([], $this->fetcher->get());
54
+    }
55
+
56
+    public function testNoInternet(): void {
57
+        $this->config
58
+            ->method('getSystemValueBool')
59
+            ->willReturnCallback(function ($var, $default) {
60
+                if ($var === 'has_internet_connection') {
61
+                    return false;
62
+                }
63
+                return $default;
64
+            });
65
+        $this->config
66
+            ->method('getSystemValueString')
67
+            ->willReturnCallback(function ($var, $default) {
68
+                return $default;
69
+            });
70
+        $this->appData
71
+            ->expects($this->never())
72
+            ->method('getFolder');
73
+
74
+        $this->assertEquals([], $this->fetcher->get());
75
+    }
76
+
77
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataGetETag')]
78
+    public function testGetEtag(?string $expected, bool $throws, string $content = ''): void {
79
+        $folder = $this->createMock(ISimpleFolder::class);
80
+        if (!$throws) {
81
+            $file = $this->createMock(ISimpleFile::class);
82
+            $file->expects($this->once())
83
+                ->method('getContent')
84
+                ->willReturn($content);
85
+            $folder->expects($this->once())
86
+                ->method('getFile')
87
+                ->with('discover.json')
88
+                ->willReturn($file);
89
+        } else {
90
+            $folder->expects($this->once())
91
+                ->method('getFile')
92
+                ->with('discover.json')
93
+                ->willThrowException(new NotFoundException(''));
94
+        }
95
+
96
+        $this->appData->expects($this->once())
97
+            ->method('getFolder')
98
+            ->with('/')
99
+            ->willReturn($folder);
100
+
101
+        $etag = $this->fetcher->getETag();
102
+        $this->assertEquals($expected, $etag);
103
+        if ($expected !== null) {
104
+            $this->assertTrue(gettype($etag) === 'string');
105
+        }
106
+    }
107
+
108
+    public static function dataGetETag(): array {
109
+        return [
110
+            'file not found' => [null, true],
111
+            'empty file' => [null, false, ''],
112
+            'missing etag' => [null, false, '{ "foo": "bar" }'],
113
+            'valid etag' => ['test', false, '{ "ETag": "test" }'],
114
+            'numeric etag' => ['132', false, '{ "ETag": 132 }'],
115
+        ];
116
+    }
117 117
 }
Please login to merge, or discard this patch.