mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add unit test for class Point
This commit is contained in:
parent
a709b3afb6
commit
ebff36d257
119
src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php
Normal file
119
src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Tests\Doctrine\Model;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
|
||||
/**
|
||||
* Test the point model methods
|
||||
*
|
||||
* @author Julien Minet <julien.minet@champs-libres.coop>
|
||||
*/
|
||||
class ExportControllerTest extends KernelTestCase
|
||||
{
|
||||
|
||||
public function testToWKT()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);
|
||||
|
||||
$this->assertEquals($point->toWKT(),'SRID=4326;POINT(4.8634 50.47382)');
|
||||
}
|
||||
|
||||
public function testToGeojson()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);
|
||||
|
||||
$this->assertEquals($point->toGeoJson(),'{"type":"Point","coordinates":[4.8634,50.47382]}');
|
||||
}
|
||||
|
||||
public function testToArrayGeoJson()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);
|
||||
|
||||
$this->assertEquals(
|
||||
$point->toArrayGeoJson(),
|
||||
[
|
||||
'type' => 'Point',
|
||||
'coordinates' => [4.8634, 50.47382]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function testJsonSerialize()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);
|
||||
|
||||
$this->assertEquals(
|
||||
$point->jsonSerialize(),
|
||||
[
|
||||
'type' => 'Point',
|
||||
'coordinates' => [4.8634, 50.47382]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromGeoJson()
|
||||
{
|
||||
$geojson = '{"type":"Point","coordinates":[4.8634,50.47382]}';
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);;
|
||||
|
||||
$this->assertEquals($point, Point::fromGeoJson($geojson));
|
||||
}
|
||||
|
||||
public function testFromLonLat()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);;
|
||||
|
||||
$this->assertEquals($point, Point::fromLonLat($lon, $lat));
|
||||
}
|
||||
|
||||
public function testFromArrayGeoJson()
|
||||
{
|
||||
$array = [
|
||||
'type' => 'Point',
|
||||
'coordinates' => [4.8634, 50.47382]
|
||||
];
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);;
|
||||
|
||||
$this->assertEquals($point, Point::fromArrayGeoJson($array));
|
||||
}
|
||||
|
||||
public function testGetLat()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);;
|
||||
|
||||
$this->assertEquals($lat, $point->getLat());
|
||||
}
|
||||
|
||||
public function testGetLon()
|
||||
{
|
||||
$lon = 4.8634;
|
||||
$lat = 50.47382;
|
||||
$point = $this->preparePoint($lon, $lat);;
|
||||
|
||||
$this->assertEquals($lon, $point->getLon());
|
||||
}
|
||||
|
||||
private function preparePoint($lon, $lat)
|
||||
{
|
||||
return Point::fromLonLat($lon, $lat);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user