Improved some tests

This commit is contained in:
Alejandro Celaya 2022-03-14 19:41:33 +01:00
parent 6a671760da
commit 1449e24b66
3 changed files with 10 additions and 7 deletions

View file

@ -139,7 +139,7 @@
"test:api": "bin/test/run-api-tests.sh", "test:api": "bin/test/run-api-tests.sh",
"test:api:ci": "GENERATE_COVERAGE=yes composer test:api", "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: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: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: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", "infect:ci": "@parallel infect:ci:unit infect:ci:db infect:ci:api",

View file

@ -13,7 +13,7 @@ class GeolocationDbUpdateFailedException extends RuntimeException implements Exc
{ {
private bool $olderDbExists; 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); parent::__construct($message, $code, $previous);
} }
@ -47,7 +47,7 @@ class GeolocationDbUpdateFailedException extends RuntimeException implements Exc
$e = new self(sprintf( $e = new self(sprintf(
'Build epoch with value "%s" from existing geolocation database, could not be parsed to integer.', 'Build epoch with value "%s" from existing geolocation database, could not be parsed to integer.',
$buildEpoch, $buildEpoch,
)); ), 0, null);
$e->olderDbExists = true; $e->olderDbExists = true;
return $e; return $e;

View file

@ -30,6 +30,7 @@ class GeolocationDbUpdaterTest extends TestCase
private ObjectProphecy $dbUpdater; private ObjectProphecy $dbUpdater;
private ObjectProphecy $geoLiteDbReader; private ObjectProphecy $geoLiteDbReader;
private TrackingOptions $trackingOptions; private TrackingOptions $trackingOptions;
private ObjectProphecy $lock;
public function setUp(): void public function setUp(): void
{ {
@ -38,11 +39,11 @@ class GeolocationDbUpdaterTest extends TestCase
$this->trackingOptions = new TrackingOptions(); $this->trackingOptions = new TrackingOptions();
$locker = $this->prophesize(Lock\LockFactory::class); $locker = $this->prophesize(Lock\LockFactory::class);
$lock = $this->prophesize(Lock\LockInterface::class); $this->lock = $this->prophesize(Lock\LockInterface::class);
$lock->acquire(true)->willReturn(true); $this->lock->acquire(true)->willReturn(true);
$lock->release()->will(function (): void { $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->geolocationDbUpdater = new GeolocationDbUpdater(
$this->dbUpdater->reveal(), $this->dbUpdater->reveal(),
@ -75,6 +76,8 @@ class GeolocationDbUpdaterTest extends TestCase
$fileExists->shouldHaveBeenCalledOnce(); $fileExists->shouldHaveBeenCalledOnce();
$getMeta->shouldNotHaveBeenCalled(); $getMeta->shouldNotHaveBeenCalled();
$download->shouldHaveBeenCalledOnce(); $download->shouldHaveBeenCalledOnce();
$this->lock->acquire(true)->shouldHaveBeenCalledOnce();
$this->lock->release()->shouldHaveBeenCalledOnce();
} }
/** /**