From 1449e24b66631be34ca38174444e69aacc51f9da Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 14 Mar 2022 19:41:33 +0100 Subject: [PATCH] Improved some tests --- composer.json | 2 +- .../Exception/GeolocationDbUpdateFailedException.php | 4 ++-- module/CLI/test/Util/GeolocationDbUpdaterTest.php | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 44b7ab91..4d240acb 100644 --- a/composer.json +++ b/composer.json @@ -139,7 +139,7 @@ "test:api": "bin/test/run-api-tests.sh", "test:api:ci": "GENERATE_COVERAGE=yes composer test:api", "infect:ci:base": "infection --threads=4 --log-verbosity=default --only-covered --only-covering-test-cases --skip-initial-tests", - "infect:ci:unit": "@infect:ci:base --coverage=build/coverage-unit --min-msi=85", + "infect:ci:unit": "@infect:ci:base --coverage=build/coverage-unit --min-msi=84", "infect:ci:db": "@infect:ci:base --coverage=build/coverage-db --min-msi=95 --configuration=infection-db.json", "infect:ci:api": "@infect:ci:base --coverage=build/coverage-api --min-msi=80 --configuration=infection-api.json", "infect:ci": "@parallel infect:ci:unit infect:ci:db infect:ci:api", diff --git a/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php b/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php index 0c5ef184..ef59d225 100644 --- a/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php +++ b/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php @@ -13,7 +13,7 @@ class GeolocationDbUpdateFailedException extends RuntimeException implements Exc { private bool $olderDbExists; - private function __construct(string $message, int $code = 0, ?Throwable $previous = null) + private function __construct(string $message, int $code, ?Throwable $previous) { parent::__construct($message, $code, $previous); } @@ -47,7 +47,7 @@ class GeolocationDbUpdateFailedException extends RuntimeException implements Exc $e = new self(sprintf( 'Build epoch with value "%s" from existing geolocation database, could not be parsed to integer.', $buildEpoch, - )); + ), 0, null); $e->olderDbExists = true; return $e; diff --git a/module/CLI/test/Util/GeolocationDbUpdaterTest.php b/module/CLI/test/Util/GeolocationDbUpdaterTest.php index 83340fc5..c5e3bdb4 100644 --- a/module/CLI/test/Util/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/Util/GeolocationDbUpdaterTest.php @@ -30,6 +30,7 @@ class GeolocationDbUpdaterTest extends TestCase private ObjectProphecy $dbUpdater; private ObjectProphecy $geoLiteDbReader; private TrackingOptions $trackingOptions; + private ObjectProphecy $lock; public function setUp(): void { @@ -38,11 +39,11 @@ class GeolocationDbUpdaterTest extends TestCase $this->trackingOptions = new TrackingOptions(); $locker = $this->prophesize(Lock\LockFactory::class); - $lock = $this->prophesize(Lock\LockInterface::class); - $lock->acquire(true)->willReturn(true); - $lock->release()->will(function (): void { + $this->lock = $this->prophesize(Lock\LockInterface::class); + $this->lock->acquire(true)->willReturn(true); + $this->lock->release()->will(function (): void { }); - $locker->createLock(Argument::type('string'))->willReturn($lock->reveal()); + $locker->createLock(Argument::type('string'))->willReturn($this->lock->reveal()); $this->geolocationDbUpdater = new GeolocationDbUpdater( $this->dbUpdater->reveal(), @@ -75,6 +76,8 @@ class GeolocationDbUpdaterTest extends TestCase $fileExists->shouldHaveBeenCalledOnce(); $getMeta->shouldNotHaveBeenCalled(); $download->shouldHaveBeenCalledOnce(); + $this->lock->acquire(true)->shouldHaveBeenCalledOnce(); + $this->lock->release()->shouldHaveBeenCalledOnce(); } /**