-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
phpunit-bootstrap.php
99 lines (71 loc) · 3.62 KB
/
phpunit-bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
use Brick\Geo\Engine\PDOEngine;
use Brick\Geo\Engine\SQLite3Engine;
use Brick\Geo\Engine\GEOSEngine;
(function() {
require 'vendor/autoload.php';
$engine = getenv('ENGINE');
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;
} else {
switch ($engine) {
case 'PDO_MYSQL':
$emulatePrepares = getenv('EMULATE_PREPARES') === 'ON';
echo 'Using PDOEngine for MySQL' . PHP_EOL;
echo 'with emulated prepares ' . ($emulatePrepares ? 'ON' : 'OFF') . 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;
$engine = new PDOEngine($pdo);
break;
case 'PDO_PGSQL':
echo 'Using PDOEngine for PostgreSQL' . 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();
echo 'PostgreSQL version: ' . $version . PHP_EOL;
$statement = $pdo->query('SELECT PostGIS_Version()');
$version = $statement->fetchColumn();
echo 'PostGIS version: ' . $version . PHP_EOL;
$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;
exit(1);
}
$GLOBALS['GEOMETRY_ENGINE'] = $engine;
}
})();