mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Migrated VisitToLocationHelperTest to use PHPUnit mocks
This commit is contained in:
parent
04419a7242
commit
d3af51f684
@ -4,10 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Core\Visit\Geolocation;
|
namespace ShlinkioTest\Shlink\Core\Visit\Geolocation;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||||
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
|
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
|
||||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||||
@ -18,15 +16,13 @@ use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
|||||||
|
|
||||||
class VisitToLocationHelperTest extends TestCase
|
class VisitToLocationHelperTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private VisitToLocationHelper $helper;
|
private VisitToLocationHelper $helper;
|
||||||
private ObjectProphecy $ipLocationResolver;
|
private MockObject $ipLocationResolver;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->ipLocationResolver = $this->prophesize(IpLocationResolverInterface::class);
|
$this->ipLocationResolver = $this->createMock(IpLocationResolverInterface::class);
|
||||||
$this->helper = new VisitToLocationHelper($this->ipLocationResolver->reveal());
|
$this->helper = new VisitToLocationHelper($this->ipLocationResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +34,7 @@ class VisitToLocationHelperTest extends TestCase
|
|||||||
IpCannotBeLocatedException $expectedException,
|
IpCannotBeLocatedException $expectedException,
|
||||||
): void {
|
): void {
|
||||||
$this->expectExceptionObject($expectedException);
|
$this->expectExceptionObject($expectedException);
|
||||||
$this->ipLocationResolver->resolveIpLocation(Argument::cetera())->shouldNotBeCalled();
|
$this->ipLocationResolver->expects($this->never())->method('resolveIpLocation');
|
||||||
|
|
||||||
$this->helper->resolveVisitLocation($visit);
|
$this->helper->resolveVisitLocation($visit);
|
||||||
}
|
}
|
||||||
@ -58,8 +54,7 @@ class VisitToLocationHelperTest extends TestCase
|
|||||||
$e = new WrongIpException('');
|
$e = new WrongIpException('');
|
||||||
|
|
||||||
$this->expectExceptionObject(IpCannotBeLocatedException::forError($e));
|
$this->expectExceptionObject(IpCannotBeLocatedException::forError($e));
|
||||||
$this->ipLocationResolver->resolveIpLocation(Argument::cetera())->willThrow($e)
|
$this->ipLocationResolver->expects($this->once())->method('resolveIpLocation')->willThrowException($e);
|
||||||
->shouldBeCalledOnce();
|
|
||||||
|
|
||||||
$this->helper->resolveVisitLocation(Visit::forBasePath(new Visitor('foo', 'bar', '1.2.3.4', '')));
|
$this->helper->resolveVisitLocation(Visit::forBasePath(new Visitor('foo', 'bar', '1.2.3.4', '')));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user