Updated amount of days to wait for the GeoLite2 database to be updated

This commit is contained in:
Alejandro Celaya 2019-04-14 13:18:03 +02:00
parent 0f48dd567f
commit 6613cb5c60
2 changed files with 12 additions and 12 deletions

View file

@ -30,7 +30,7 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
{ {
try { try {
$meta = $this->geoLiteDbReader->metadata(); $meta = $this->geoLiteDbReader->metadata();
if ($this->buildIsOlderThanOneWeek($meta->__get('buildEpoch'))) { if ($this->buildIsTooOld($meta->__get('buildEpoch'))) {
$this->downloadNewDb(true, $mustBeUpdated, $handleProgress); $this->downloadNewDb(true, $mustBeUpdated, $handleProgress);
} }
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
@ -39,11 +39,11 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
} }
} }
private function buildIsOlderThanOneWeek(int $buildTimestamp): bool private function buildIsTooOld(int $buildTimestamp): bool
{ {
$buildDate = Chronos::createFromTimestamp($buildTimestamp); $buildDate = Chronos::createFromTimestamp($buildTimestamp);
$now = Chronos::now(); $now = Chronos::now();
return $now->gt($buildDate->addDays(7)); return $now->gt($buildDate->addDays(35));
} }
/** /**
@ -55,7 +55,7 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
callable $handleProgress = null callable $handleProgress = null
): void { ): void {
if ($mustBeUpdated !== null) { if ($mustBeUpdated !== null) {
$mustBeUpdated(); $mustBeUpdated($olderDbExists);
} }
try { try {

View file

@ -64,7 +64,7 @@ class GeolocationDbUpdaterTest extends TestCase
/** /**
* @test * @test
* @dataProvider provideDaysBiggerThanSeven * @dataProvider provideBigDays
*/ */
public function exceptionIsThrownWhenOlderDbIsTooOldAndDownloadFails(int $days): void public function exceptionIsThrownWhenOlderDbIsTooOldAndDownloadFails(int $days): void
{ {
@ -96,17 +96,17 @@ class GeolocationDbUpdaterTest extends TestCase
$download->shouldHaveBeenCalledOnce(); $download->shouldHaveBeenCalledOnce();
} }
public function provideDaysBiggerThanSeven(): iterable public function provideBigDays(): iterable
{ {
yield [8]; yield [36];
yield [9]; yield [50];
yield [10]; yield [75];
yield [100]; yield [100];
} }
/** /**
* @test * @test
* @dataProvider provideDaysSmallerThanSeven * @dataProvider provideSmallDays
*/ */
public function databaseIsNotUpdatedIfItIsYoungerThanOneWeek(int $days): void public function databaseIsNotUpdatedIfItIsYoungerThanOneWeek(int $days): void
{ {
@ -130,9 +130,9 @@ class GeolocationDbUpdaterTest extends TestCase
$download->shouldNotHaveBeenCalled(); $download->shouldNotHaveBeenCalled();
} }
public function provideDaysSmallerThanSeven(): iterable public function provideSmallDays(): iterable
{ {
return map(range(0, 6), function (int $days) { return map(range(0, 34), function (int $days) {
return [$days]; return [$days];
}); });
} }