Update to PHPStan 2.0

This commit is contained in:
Alejandro Celaya
2024-11-12 10:22:23 +01:00
parent 15cb3bb73c
commit 9a69d06531
18 changed files with 52 additions and 55 deletions

View File

@@ -41,22 +41,24 @@ class GeolocationDbUpdaterTest extends TestCase
#[Test]
public function properResultIsReturnedWhenLicenseIsMissing(): void
{
$mustBeUpdated = fn () => self::assertTrue(true);
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(false);
$this->dbUpdater->expects($this->once())->method('downloadFreshCopy')->willThrowException(
new MissingLicenseException(''),
);
$this->geoLiteDbReader->expects($this->never())->method('metadata');
$result = $this->geolocationDbUpdater()->checkDbUpdate($mustBeUpdated);
$isCalled = false;
$result = $this->geolocationDbUpdater()->checkDbUpdate(function () use (&$isCalled): void {
$isCalled = true;
});
self::assertTrue($isCalled);
self::assertEquals(GeolocationResult::LICENSE_MISSING, $result);
}
#[Test]
public function exceptionIsThrownWhenOlderDbDoesNotExistAndDownloadFails(): void
{
$mustBeUpdated = fn () => self::assertTrue(true);
$prev = new DbUpdateException('');
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(false);
@@ -65,14 +67,17 @@ class GeolocationDbUpdaterTest extends TestCase
)->willThrowException($prev);
$this->geoLiteDbReader->expects($this->never())->method('metadata');
$isCalled = false;
try {
$this->geolocationDbUpdater()->checkDbUpdate($mustBeUpdated);
$this->geolocationDbUpdater()->checkDbUpdate(function () use (&$isCalled): void {
$isCalled = true;
});
self::fail();
} catch (Throwable $e) {
/** @var GeolocationDbUpdateFailedException $e */
self::assertInstanceOf(GeolocationDbUpdateFailedException::class, $e);
self::assertSame($prev, $e->getPrevious());
self::assertFalse($e->olderDbExists());
self::assertTrue($isCalled);
}
}
@@ -92,7 +97,6 @@ class GeolocationDbUpdaterTest extends TestCase
$this->geolocationDbUpdater()->checkDbUpdate();
self::fail();
} catch (Throwable $e) {
/** @var GeolocationDbUpdateFailedException $e */
self::assertInstanceOf(GeolocationDbUpdateFailedException::class, $e);
self::assertSame($prev, $e->getPrevious());
self::assertTrue($e->olderDbExists());