Skip to content

Commit

Permalink
Fix tests & Psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Oct 10, 2021
1 parent 71ca2a5 commit 022a01d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 184 deletions.
91 changes: 4 additions & 87 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
php-version:
- "7.4"
- "8.0"
emulate-prepares:
- "ON"
- "OFF"

services:
mysql:
Expand Down Expand Up @@ -64,17 +61,15 @@ jobs:
- name: Run PHPUnit
run: vendor/bin/phpunit
env:
ENGINE: PDO_MYSQL
EMULATE_PREPARES: ${{ matrix.emulate-prepares }}
DRIVER: PDO_MYSQL
if: ${{ matrix.php-version != '8.0' }}

- name: Run PHPUnit with coverage
run: |
mkdir -p mkdir -p build/logs
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: PDO_MYSQL
EMULATE_PREPARES: ${{ matrix.emulate-prepares }}
DRIVER: PDO_MYSQL
if: ${{ matrix.php-version == '8.0' }}

- name: Upload coverage report to Coveralls
Expand All @@ -91,9 +86,6 @@ jobs:
matrix:
php-version:
- "8.0"
emulate-prepares:
- "ON"
- "OFF"

services:
mariadb:
Expand Down Expand Up @@ -124,8 +116,7 @@ jobs:
mkdir -p mkdir -p build/logs
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: PDO_MYSQL
EMULATE_PREPARES: ${{ matrix.emulate-prepares }}
DRIVER: PDO_MYSQL

- name: Upload coverage report to Coveralls
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
Expand Down Expand Up @@ -167,81 +158,7 @@ jobs:
mkdir -p mkdir -p build/logs
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: PDO_PGSQL

- name: Upload coverage report to Coveralls
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

phpunit-sqlite:
name: PHPUnit SQLite
runs-on: ubuntu-20.04

strategy:
matrix:
php-version:
- "8.0"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: sqlite3
ini-values: sqlite3.extension_dir=/usr/lib/x86_64-linux-gnu
coverage: xdebug

- name: Install SpatiaLite
run: sudo apt install libsqlite3-mod-spatialite

- name: Install composer dependencies
uses: "ramsey/composer-install@v1"

- name: Run PHPUnit with coverage
run: |
mkdir -p mkdir -p build/logs
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: SQLite3

- name: Upload coverage report to Coveralls
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

phpunit-geos:
name: PHPUnit GEOS
runs-on: ubuntu-20.04

strategy:
matrix:
php-version:
- "7.4"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: geos
coverage: xdebug

- name: Install composer dependencies
uses: "ramsey/composer-install@v1"

- name: Run PHPUnit with coverage
run: |
mkdir -p mkdir -p build/logs
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: GEOS
DRIVER: PDO_PGSQL

- name: Upload coverage report to Coveralls
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"doctrine/orm": "^2.0"
},
"require-dev": {
"doctrine/cache": "^1.11",
"doctrine/data-fixtures": "^1.0",
"phpunit/phpunit": "^8.0 || ^9.0",
"php-coveralls/php-coveralls": "^2.0",
Expand Down
90 changes: 12 additions & 78 deletions phpunit-bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php

use Brick\Geo\Doctrine\Types;
use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\PDOEngine;
use Brick\Geo\Engine\SQLite3Engine;
use Brick\Geo\Engine\GEOSEngine;
use Doctrine\DBAL\Types\Type;

(function() {
Expand All @@ -27,141 +23,79 @@
Type::addType('point', Types\PointType::class);
Type::addType('polygon', Types\PolygonType::class);

$engine = getenv('ENGINE');
$driver = getenv('DRIVER');

if ($engine === false) {
echo 'WARNING: running tests without a geometry engine.' . PHP_EOL;
echo 'All tests requiring a geometry engine will be skipped.' . PHP_EOL;
echo 'To run tests with a geometry engine, use: ENGINE={engine} vendor/bin/phpunit' . PHP_EOL;
echo 'Available engines: PDO_MYSQL, PDO_PGSQL, SQLite3, GEOS' . PHP_EOL;
if ($driver === false) {
echo 'Please set the database driver to use:' . PHP_EOL;
echo 'DRIVER={driver} vendor/bin/phpunit' . PHP_EOL;
echo 'Available drivers: PDO_MYSQL, PDO_PGSQL' . PHP_EOL;
exit(1);
} else {
switch ($engine) {
switch ($driver) {
case 'PDO_MYSQL':
$emulatePrepares = getenv('EMULATE_PREPARES') === 'ON';

echo 'Using PDOEngine for MySQL' . PHP_EOL;
echo 'with emulated prepares ' . ($emulatePrepares ? 'ON' : 'OFF') . PHP_EOL;
echo 'Using PDO_MYSQL driver' . PHP_EOL;

$pdo = new PDO('mysql:host=127.0.0.1;port=3306', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulatePrepares);

$pdo->exec('DROP DATABASE IF EXISTS geo_tests');
$pdo->exec('DROP DATABASE IF EXISTS geo_tests_tmp');
$pdo->exec('CREATE DATABASE geo_tests');
$pdo->exec('CREATE DATABASE geo_tests_tmp');
$pdo->exec('USE geo_tests');

$statement = $pdo->query('SELECT VERSION()');
$version = $statement->fetchColumn();

echo 'MySQL version: ' . $version . PHP_EOL;

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

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

// doctrine/dbal >= 2.13.0
$GLOBALS['db_driver'] = 'pdo_mysql';
$GLOBALS['db_user'] = 'root';
$GLOBALS['db_dbname'] = 'geo_tests';

$GLOBALS['tmpdb_driver'] = 'pdo_mysql';
$GLOBALS['tmpdb_user'] = 'root';
$GLOBALS['tmpdb_dbname'] = 'geo_tests_tmp';

$engine = new PDOEngine($pdo);
break;

case 'PDO_PGSQL':
echo 'Using PDOEngine for PostgreSQL' . PHP_EOL;
echo 'Using PDO_PGSQL driver' . PHP_EOL;

$pdo = new PDO('pgsql:host=localhost', 'postgres', 'postgres');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec('CREATE EXTENSION IF NOT EXISTS postgis;');
$pdo->exec('DROP DATABASE IF EXISTS geo_tests');
$pdo->exec('DROP DATABASE IF EXISTS geo_tests_tmp');
$pdo->exec('CREATE DATABASE geo_tests');
$pdo->exec('CREATE DATABASE geo_tests_tmp');

$statement = $pdo->query('SELECT version()');
$version = $statement->fetchColumn(0);
$version = $statement->fetchColumn();

echo 'PostgreSQL version: ' . $version . PHP_EOL;

$statement = $pdo->query('SELECT PostGIS_Version()');
$version = $statement->fetchColumn(0);
$version = $statement->fetchColumn();

echo 'PostGIS version: ' . $version . PHP_EOL;

// 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';

// doctrine/dbal >= 2.13.0
$GLOBALS['db_driver'] = 'pdo_pgsql';
$GLOBALS['db_user'] = 'postgres';
$GLOBALS['db_dbname'] = 'geo_tests';

$GLOBALS['tmpdb_driver'] = 'pdo_pgsql';
$GLOBALS['tmpdb_user'] = 'postgres';
$GLOBALS['tmpdb_dbname'] = 'geo_tests_tmp';

$engine = new PDOEngine($pdo);
break;

case 'SQLite3':
echo 'Using SQLite3Engine' . PHP_EOL;

$sqlite3 = new SQLite3(':memory:');
$sqlite3->enableExceptions(true);

$sqliteVersion = $sqlite3->querySingle('SELECT sqlite_version()');
echo 'SQLite version: ' . $sqliteVersion . PHP_EOL;

$sqlite3->loadExtension('mod_spatialite.so');

$spatialiteVersion = $sqlite3->querySingle('SELECT spatialite_version()');
echo 'SpatiaLite version: ' . $spatialiteVersion . PHP_EOL;

$engine = new SQLite3Engine($sqlite3);
break;

case 'GEOS':
echo 'Using GEOSEngine' . PHP_EOL;
echo 'GEOS version: ' . GEOSVersion() . PHP_EOL;

$engine = new GEOSEngine();
break;

default:
echo 'Unknown engine: ' . $engine . PHP_EOL;
echo 'Unknown driver: ' . $driver . PHP_EOL;
exit(1);
}

GeometryEngineRegistry::set($engine);
}
})();
4 changes: 2 additions & 2 deletions src/Types/GeometryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getName()

public function getSQLDeclaration(array $column, AbstractPlatform $platform)
{
if ($platform instanceof PostgreSqlPlatform) {
if ($platform->getName() === 'postgresql') {
return 'GEOMETRY';
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
{
if ($platform instanceof MySqlPlatform) {
if ($platform->getName() === 'mysql') {
$sqlExpr = sprintf('BINARY %s', $sqlExpr);
}

Expand Down
28 changes: 11 additions & 17 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@

use Brick\Geo\Point;
use Brick\Geo\Doctrine\Tests\Fixtures;
use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\PDOEngine;

use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\Setup;
use Doctrine\Tests\DbalFunctionalTestCase;
use PHPUnit\Framework\TestCase;

/**
* Base class for Doctrine types functional test cases.
*/
abstract class FunctionalTestCase extends DbalFunctionalTestCase
abstract class FunctionalTestCase extends TestCase
{
private AbstractPlatform $platform;

Expand All @@ -32,21 +31,15 @@ abstract class FunctionalTestCase extends DbalFunctionalTestCase

private ORMExecutor $ormExecutor;

/** @var Connection */
private $connection;

protected function setUp(): void
{
if (! GeometryEngineRegistry::has()) {
self::markTestSkipped('This test requires a connection to a database.');
}

$engine = GeometryEngineRegistry::get();

if (! $engine instanceof PDOEngine) {
self::markTestSkipped('This test currently only works with a PDO connection.');
}

parent::setUp();

$this->platform = $this->_conn->getDatabasePlatform();
$this->connection = TestUtil::getConnection();
$this->platform = $this->connection->getDatabasePlatform();

$this->platform->registerDoctrineTypeMapping('geometry', 'binary');
$this->platform->registerDoctrineTypeMapping('linestring', 'binary');
Expand All @@ -58,14 +51,15 @@ protected function setUp(): void

switch ($this->platform->getName()) {
case 'postgresql':
$this->_conn->executeQuery('CREATE EXTENSION IF NOT EXISTS postgis;');
$this->connection->executeQuery('CREATE EXTENSION IF NOT EXISTS postgis;');
break;
}

$this->fixtureLoader = new Loader();

$config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/Fixtures'], false);

$this->em = EntityManager::create($this->_conn, $config, $this->platform->getEventManager());
$this->em = EntityManager::create($this->connection, $config, $this->platform->getEventManager());
$schemaTool = new SchemaTool($this->em);

$schemaTool->updateSchema([
Expand Down
Loading

0 comments on commit 022a01d

Please sign in to comment.