Skip to content

Commit

Permalink
Merge 38cecde into ebba501
Browse files Browse the repository at this point in the history
  • Loading branch information
cevou committed Jan 21, 2015
2 parents ebba501 + 38cecde commit 0e2ac9f
Show file tree
Hide file tree
Showing 26 changed files with 1,001 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ env:
- ENGINE=GEOS

before_script:
- if [[ $ENGINE = PDO_PGSQL ]]; then psql -c 'create database geo_tests;' -U postgres; fi;
- if [[ $ENGINE = PDO_PGSQL ]]; then psql -c 'create database geo_tests_tmp;' -U postgres; fi;
- if [[ $ENGINE = PDO_MYSQL ]]; then bash .travis.install-mysql.sh; fi;
- if [[ $ENGINE = PDO_MYSQL ]]; then mysql -e 'create database geo_tests;'; fi;
- if [[ $ENGINE = PDO_MYSQL ]]; then mysql -e 'create database geo_tests_tmp;'; fi;
- if [[ $ENGINE = GEOS ]]; then bash .travis.install-geos.sh; fi;
- if [[ $ENGINE = SQLite3 ]]; then bash .travis.install-sqlite3.sh; fi;
- composer install
- composer install --prefer-source

script:
- mkdir -p build/logs
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require-dev": {
"brick/reflection": "dev-master",
"doctrine/orm": "*",
"doctrine/data-fixtures": "*",
"phpunit/phpunit": "*",
"satooshi/php-coveralls": "dev-master"
},
Expand Down
53 changes: 51 additions & 2 deletions phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@
use Brick\Geo\Engine\PDOEngine;
use Brick\Geo\Engine\SQLite3Engine;
use Brick\Geo\Engine\GEOSEngine;
use Doctrine\DBAL\Types\Type;

/** @var \Composer\Autoload\ClassLoader $classLoader */
$classLoader = require 'vendor/autoload.php';

//Add namespace for doctrine base tests
$classLoader->addPsr4('Doctrine\\Tests\\', [
__DIR__ . '/vendor/doctrine/orm/tests/Doctrine/Tests',
__DIR__ . '/vendor/doctrine/dbal/tests/Doctrine/Tests'
]);
$classLoader->loadClass('Doctrine\Tests\DbalFunctionalTestCase');
$classLoader->loadClass('Doctrine\Tests\DBAL\Mocks\MockPlatform');

Type::addType('geometry', 'Brick\Geo\Doctrine\Types\GeometryType');
Type::addType('linestring', 'Brick\Geo\Doctrine\Types\LineStringType');
Type::addType('multilinestring', 'Brick\Geo\Doctrine\Types\MultiLineStringType');
Type::addType('multipoint', 'Brick\Geo\Doctrine\Types\MultiPointType');
Type::addType('multipolygon', 'Brick\Geo\Doctrine\Types\MultiPolygonType');
Type::addType('point', 'Brick\Geo\Doctrine\Types\PointType');
Type::addType('polygon', 'Brick\Geo\Doctrine\Types\PolygonType');

require 'vendor/autoload.php';

/**
* @return GeometryEngine
Expand All @@ -17,12 +36,42 @@ function createGeometryEngine()
case 'PDO_MYSQL':
$pdo = new PDO('mysql:host=localhost', 'root', '');
$engine = new PDOEngine($pdo);

//Connect data for doctrine integration tests
$GLOBALS['db_type'] = 'pdo_mysql';
$GLOBALS['db_host'] = 'localhost';
$GLOBALS['db_port'] = 3306;
$GLOBALS['db_username'] = 'root';
$GLOBALS['db_password'] = '';
$GLOBALS['db_name'] = 'geo_tests';

$GLOBALS['tmpdb_type'] = 'pdo_mysql';
$GLOBALS['tmpdb_host'] = 'localhost';
$GLOBALS['tmpdb_port'] = 3306;
$GLOBALS['tmpdb_username'] = 'root';
$GLOBALS['tmpdb_password'] = '';
$GLOBALS['tmpdb_name'] = 'geo_tests_tmp';
break;

case 'PDO_PGSQL':
$pdo = new PDO('pgsql:host=localhost', 'postgres', '');
$pdo = new PDO('pgsql:host=localhost', 'postgres', 'postgres');
$pdo->exec('CREATE EXTENSION IF NOT EXISTS postgis;');
$engine = new PDOEngine($pdo);

//Connect data for doctrine integration tests
$GLOBALS['db_type'] = 'pdo_pgsql';
$GLOBALS['db_host'] = 'localhost';
$GLOBALS['db_port'] = 5432;
$GLOBALS['db_username'] = 'postgres';
$GLOBALS['db_password'] = 'postgres';
$GLOBALS['db_name'] = 'geo_tests';

$GLOBALS['tmpdb_type'] = 'pdo_pgsql';
$GLOBALS['tmpdb_host'] = 'localhost';
$GLOBALS['tmpdb_port'] = 5432;
$GLOBALS['tmpdb_username'] = 'postgres';
$GLOBALS['tmpdb_password'] = 'postgres';
$GLOBALS['tmpdb_name'] = 'geo_tests_tmp';
break;

case 'SQLite3':
Expand Down
13 changes: 13 additions & 0 deletions src/Doctrine/Types/GeometryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function getName()
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
if ($platform->getName() === 'postgresql') {
return "GEOMETRY";
}
return strtoupper($this->getName());
}

Expand Down Expand Up @@ -110,4 +113,14 @@ public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}

/**
* {@inheritdoc}
*/
public function getBindingType()
{
return \PDO::PARAM_LOB;
}


}
23 changes: 23 additions & 0 deletions tests/Doctrine/DataFixtures/LoadGeometryData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\Point;
use Brick\Geo\Tests\Doctrine\Fixtures\GeometryEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadGeometryData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = new GeometryEntity();
$point1->setGeometry(Point::factory(0, 0));

$manager->persist($point1);
$manager->flush();
}
}
28 changes: 28 additions & 0 deletions tests/Doctrine/DataFixtures/LoadLineStringData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\LineString;
use Brick\Geo\Point;
use Brick\Geo\Tests\Doctrine\Fixtures\LineStringEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadLineStringData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = Point::factory(0,0);
$point2 = Point::factory(1,0);
$point3 = Point::factory(1,1);

$lineString1 = new LineStringEntity();
$lineString1->setLineString(LineString::factory([ $point1, $point2, $point3 ]));

$manager->persist($lineString1);
$manager->flush();
}
}
35 changes: 35 additions & 0 deletions tests/Doctrine/DataFixtures/LoadMultiLineStringData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\LineString;
use Brick\Geo\MultiLineString;
use Brick\Geo\Point;
use Brick\Geo\Tests\Doctrine\Fixtures\MultiLineStringEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadMultiLineStringData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = Point::factory(0,0);
$point2 = Point::factory(1,0);
$point3 = Point::factory(1,1);
$lineString1 = LineString::factory([ $point1, $point2, $point3 ]);

$point4 = Point::factory(2,2);
$point5 = Point::factory(3,2);
$point6 = Point::factory(3,3);
$lineString2 = LineString::factory([ $point4, $point5, $point6 ]);

$multilineString1 = new MultiLineStringEntity();
$multilineString1->setMultiLineString(MultiLineString::factory([ $lineString1, $lineString2 ]));

$manager->persist($multilineString1);
$manager->flush();
}
}
28 changes: 28 additions & 0 deletions tests/Doctrine/DataFixtures/LoadMultiPointData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\MultiPoint;
use Brick\Geo\Point;
use Brick\Geo\Tests\Doctrine\Fixtures\MultiPointEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadMultiPointData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = Point::factory(0,0);
$point2 = Point::factory(1,0);
$point3 = Point::factory(1,1);

$multiPoint1 = new MultiPointEntity();
$multiPoint1->setMultiPoint(MultiPoint::factory([ $point1, $point2, $point3 ]));

$manager->persist($multiPoint1);
$manager->flush();
}
}
42 changes: 42 additions & 0 deletions tests/Doctrine/DataFixtures/LoadMultiPolygonData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\LinearRing;
use Brick\Geo\MultiPolygon;
use Brick\Geo\Point;
use Brick\Geo\Polygon;
use Brick\Geo\Tests\Doctrine\Fixtures\MultiPolygonEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadMultiPolygonData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = Point::factory(0,0);
$point2 = Point::factory(1,0);
$point3 = Point::factory(1,1);
$point4 = Point::factory(0,1);
$point5 = Point::factory(0,0);
$ring1 = LinearRing::factory([ $point1, $point2, $point3, $point4, $point5]);
$poly1 = Polygon::factory([ $ring1 ]);

$point6 = Point::factory(2,2);
$point7 = Point::factory(3,2);
$point8 = Point::factory(3,3);
$point9 = Point::factory(2,3);
$point10 = Point::factory(2,2);
$ring2 = LinearRing::factory([ $point6, $point7, $point8, $point9, $point10]);
$poly2 = Polygon::factory([ $ring2 ]);

$multiPoly1 = new MultiPolygonEntity();
$multiPoly1->setMultiPolygon(MultiPolygon::factory([ $poly1, $poly2 ]));

$manager->persist($multiPoly1);
$manager->flush();
}
}
23 changes: 23 additions & 0 deletions tests/Doctrine/DataFixtures/LoadPointData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\Point;
use Brick\Geo\Tests\Doctrine\Fixtures\PointEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadPointData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = new PointEntity();
$point1->setPoint(Point::factory(0, 0));

$manager->persist($point1);
$manager->flush();
}
}
33 changes: 33 additions & 0 deletions tests/Doctrine/DataFixtures/LoadPolygonData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Brick\Geo\Tests\Doctrine\DataFixtures;

use Brick\Geo\LinearRing;
use Brick\Geo\Point;
use Brick\Geo\Polygon;
use Brick\Geo\Tests\Doctrine\Fixtures\PolygonEntity;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadPolygonData implements FixtureInterface {

/**
* {@inheritdoc}
*/
function load(ObjectManager $manager)
{
$point1 = Point::factory(0,0);
$point2 = Point::factory(1,0);
$point3 = Point::factory(1,1);
$point4 = Point::factory(0,1);
$point5 = Point::factory(0,0);

$ring = LinearRing::factory([ $point1, $point2, $point3, $point4, $point5]);

$poly1 = new PolygonEntity();
$poly1->setPolygon(Polygon::factory([$ring]));

$manager->persist($poly1);
$manager->flush();
}
}
Loading

0 comments on commit 0e2ac9f

Please sign in to comment.