mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 19:59:04 +03:00
Added test to cover new IP resolution API limits
This commit is contained in:
parent
ed859767a8
commit
110e8cb78d
2 changed files with 53 additions and 0 deletions
|
@ -97,4 +97,41 @@ class ProcessVisitsCommandTest extends TestCase
|
||||||
$output = $this->commandTester->getDisplay();
|
$output = $this->commandTester->getDisplay();
|
||||||
$this->assertTrue(strpos($output, 'Ignored localhost address') > 0);
|
$this->assertTrue(strpos($output, 'Ignored localhost address') > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function sleepsEveryTimeTheApiLimitIsReached()
|
||||||
|
{
|
||||||
|
$visits = [
|
||||||
|
(new Visit())->setRemoteAddr('1.2.3.4'),
|
||||||
|
(new Visit())->setRemoteAddr('4.3.2.1'),
|
||||||
|
(new Visit())->setRemoteAddr('12.34.56.78'),
|
||||||
|
(new Visit())->setRemoteAddr('1.2.3.4'),
|
||||||
|
(new Visit())->setRemoteAddr('4.3.2.1'),
|
||||||
|
(new Visit())->setRemoteAddr('12.34.56.78'),
|
||||||
|
(new Visit())->setRemoteAddr('1.2.3.4'),
|
||||||
|
(new Visit())->setRemoteAddr('4.3.2.1'),
|
||||||
|
(new Visit())->setRemoteAddr('12.34.56.78'),
|
||||||
|
(new Visit())->setRemoteAddr('4.3.2.1'),
|
||||||
|
];
|
||||||
|
$apiLimit = 3;
|
||||||
|
|
||||||
|
$this->visitService->getUnlocatedVisits()->willReturn($visits);
|
||||||
|
$this->visitService->saveVisit(Argument::any())->will(function () {
|
||||||
|
});
|
||||||
|
|
||||||
|
$getApiLimit = $this->ipResolver->getApiLimit()->willReturn($apiLimit);
|
||||||
|
$getApiInterval = $this->ipResolver->getApiInterval()->willReturn(0);
|
||||||
|
$resolveIpLocation = $this->ipResolver->resolveIpLocation(Argument::any())->willReturn([])
|
||||||
|
->shouldBeCalledTimes(count($visits));
|
||||||
|
|
||||||
|
$this->commandTester->execute([
|
||||||
|
'command' => 'visit:process',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$getApiLimit->shouldHaveBeenCalledTimes(\count($visits));
|
||||||
|
$getApiInterval->shouldHaveBeenCalledTimes(\round(\count($visits) / $apiLimit));
|
||||||
|
$resolveIpLocation->shouldHaveBeenCalledTimes(\count($visits));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,4 +65,20 @@ class IpApiLocationResolverTest extends TestCase
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
$this->ipResolver->resolveIpLocation('1.2.3.4');
|
$this->ipResolver->resolveIpLocation('1.2.3.4');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function getApiIntervalReturnsExpectedValue()
|
||||||
|
{
|
||||||
|
$this->assertEquals(65, $this->ipResolver->getApiInterval());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function getApiLimitReturnsExpectedValue()
|
||||||
|
{
|
||||||
|
$this->assertEquals(145, $this->ipResolver->getApiLimit());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue