mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Forced explicit string casting when hydrating a VisitLocation from an array
This commit is contained in:
parent
47117d1fb7
commit
1e4de7fec4
@ -136,25 +136,25 @@ class VisitLocation extends AbstractEntity implements ArraySerializableInterface
|
||||
public function exchangeArray(array $array): void
|
||||
{
|
||||
if (\array_key_exists('country_code', $array)) {
|
||||
$this->setCountryCode($array['country_code']);
|
||||
$this->setCountryCode((string) $array['country_code']);
|
||||
}
|
||||
if (\array_key_exists('country_name', $array)) {
|
||||
$this->setCountryName($array['country_name']);
|
||||
$this->setCountryName((string) $array['country_name']);
|
||||
}
|
||||
if (\array_key_exists('region_name', $array)) {
|
||||
$this->setRegionName($array['region_name']);
|
||||
$this->setRegionName((string) $array['region_name']);
|
||||
}
|
||||
if (\array_key_exists('city', $array)) {
|
||||
$this->setCityName($array['city']);
|
||||
$this->setCityName((string) $array['city']);
|
||||
}
|
||||
if (\array_key_exists('latitude', $array)) {
|
||||
$this->setLatitude($array['latitude']);
|
||||
$this->setLatitude((string) $array['latitude']);
|
||||
}
|
||||
if (\array_key_exists('longitude', $array)) {
|
||||
$this->setLongitude($array['longitude']);
|
||||
$this->setLongitude((string) $array['longitude']);
|
||||
}
|
||||
if (\array_key_exists('time_zone', $array)) {
|
||||
$this->setTimezone($array['time_zone']);
|
||||
$this->setTimezone((string) $array['time_zone']);
|
||||
}
|
||||
}
|
||||
|
||||
|
27
module/Core/test/Entity/VisitLocationTest.php
Normal file
27
module/Core/test/Entity/VisitLocationTest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Entity;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
||||
|
||||
class VisitLocationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function valuesFoundWhenExchangingArrayAreCastToString()
|
||||
{
|
||||
$payload = [
|
||||
'latitude' => 1000.7,
|
||||
'longitude' => -2000.4,
|
||||
];
|
||||
|
||||
$location = new VisitLocation();
|
||||
$location->exchangeArray($payload);
|
||||
|
||||
$this->assertSame('1000.7', $location->getLatitude());
|
||||
$this->assertSame('-2000.4', $location->getLongitude());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user