1919use Kreait \Firebase \RemoteConfig \VersionNumber ;
2020use Kreait \Firebase \Tests \IntegrationTestCase ;
2121use PHPUnit \Framework \Attributes \DoesNotPerformAssertions ;
22- use Throwable ;
2322
2423/**
2524 * @internal
@@ -234,42 +233,17 @@ public function testValidateInvalidTemplate(): void
234233
235234 public function testPublishInvalidTemplate (): void
236235 {
237- $ version = $ this ->remoteConfig ->get ()->version ();
238-
239- if (!$ version instanceof Version) {
240- $ this ->fail ('The template has no version ' );
241- }
242-
243- $ currentVersionNumber = $ version ->versionNumber ();
244-
245236 $ template = $ this ->templateWithTooManyParameters ();
246237
247- try {
248- $ this ->remoteConfig ->validate ($ template );
249- $ this ->fail ('A ' .ValidationFailed::class.' should have been thrown ' );
250- } catch (Throwable $ e ) {
251- $ this ->assertInstanceOf (ValidationFailed::class, $ e );
252- }
253-
254- $ refetchedVersion = $ this ->remoteConfig ->get ()->version ();
255-
256- if (!$ refetchedVersion instanceof Version) {
257- $ this ->fail ('The template has no version ' );
258- }
259-
260- $ this ->assertTrue (
261- $ currentVersionNumber ->equalsTo ($ refetchedVersion ->versionNumber ()),
262- "Expected the template version to be {$ currentVersionNumber }, got {$ refetchedVersion ->versionNumber ()}" ,
263- );
238+ $ this ->expectException (ValidationFailed::class);
239+ $ this ->remoteConfig ->publish ($ template );
264240 }
265241
266242 public function testRollback (): void
267243 {
268244 $ initialVersion = $ this ->remoteConfig ->get ()->version ();
269245
270- if (!$ initialVersion instanceof Version) {
271- $ this ->fail ('The template has no version ' );
272- }
246+ $ this ->assertInstanceOf (Version::class, $ initialVersion );
273247
274248 $ initialVersionNumber = $ initialVersion ->versionNumber ();
275249
@@ -288,25 +262,18 @@ public function testRollback(): void
288262 }
289263 }
290264
291- if ($ targetVersionNumber === null ) {
292- $ this ->fail ('A previous version number should have been retrieved ' );
293- }
265+ $ this ->assertInstanceOf (VersionNumber::class, $ targetVersionNumber );
294266
295267 $ this ->remoteConfig ->rollbackToVersion ($ targetVersionNumber );
296268
297269 $ newVersion = $ this ->remoteConfig ->get ()->version ();
298270
299- if (!$ newVersion instanceof Version) {
300- $ this ->fail ('The new template has no version ' );
301- }
271+ $ this ->assertInstanceOf (Version::class, $ newVersion );
302272
303273 $ newVersionNumber = $ newVersion ->versionNumber ();
304274 $ rollbackSource = $ newVersion ->rollbackSource ();
305275
306- if (!$ rollbackSource instanceof VersionNumber) {
307- $ this ->fail ('The new template version has no rollback source ' );
308- }
309-
276+ $ this ->assertInstanceOf (VersionNumber::class, $ rollbackSource );
310277 $ this ->assertFalse ($ newVersionNumber ->equalsTo ($ initialVersionNumber ));
311278 $ this ->assertTrue ($ rollbackSource ->equalsTo ($ targetVersionNumber ));
312279 }
@@ -328,9 +295,7 @@ public function testFindVersionsWithFilters(): void
328295 {
329296 $ currentVersion = $ this ->remoteConfig ->get ()->version ();
330297
331- if (!$ currentVersion instanceof Version) {
332- $ this ->fail ('The new template has no version ' );
333- }
298+ $ this ->assertInstanceOf (Version::class, $ currentVersion );
334299
335300 $ currentVersionUpdateDate = $ currentVersion ->updatedAt ();
336301
@@ -342,27 +307,16 @@ public function testFindVersionsWithFilters(): void
342307 'limit ' => $ limit = 2 ,
343308 ];
344309
345- $ counter = 0 ;
346-
347- foreach ($ this ->remoteConfig ->listVersions ($ query ) as $ version ) {
348- ++$ counter ;
310+ $ versionCount = iterator_count ($ this ->remoteConfig ->listVersions ($ query ));
349311
350- // Protect us from an infinite loop
351- if ($ counter > $ limit ) {
352- $ this ->fail ('The query returned more values than expected ' );
353- }
354- }
355-
356- $ this ->assertLessThanOrEqual ($ limit , $ counter );
312+ $ this ->assertLessThanOrEqual ($ limit , $ versionCount );
357313 }
358314
359315 public function testGetVersion (): void
360316 {
361317 $ currentVersion = $ this ->remoteConfig ->get ()->version ();
362318
363- if (!$ currentVersion instanceof Version) {
364- $ this ->fail ('The template has no version ' );
365- }
319+ $ this ->assertInstanceOf (Version::class, $ currentVersion );
366320
367321 $ currentVersionNumber = $ currentVersion ->versionNumber ();
368322
@@ -375,9 +329,7 @@ public function testGetNonExistingVersion(): void
375329 {
376330 $ currentVersion = $ this ->remoteConfig ->get ()->version ();
377331
378- if (!$ currentVersion instanceof Version) {
379- $ this ->fail ('The template has no version ' );
380- }
332+ $ this ->assertInstanceOf (Version::class, $ currentVersion );
381333
382334 $ version = $ currentVersion ->versionNumber ();
383335 $ versionString = $ version ->__toString ();
0 commit comments