-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathphpunit-bootstrap.php
More file actions
154 lines (106 loc) · 4.69 KB
/
phpunit-bootstrap.php
File metadata and controls
154 lines (106 loc) · 4.69 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
declare(strict_types=1);
use Brick\Geo\Engine\GeosEngine;
use Brick\Geo\Engine\GeosOpEngine;
use Brick\Geo\Engine\PdoEngine;
use Brick\Geo\Engine\Sqlite3Engine;
function getOptionalEnv(string $name): ?string
{
$value = getenv($name);
return $value === false ? null : $value;
}
function getOptionalEnvOrDefault(string $name, string $default): string
{
$value = getenv($name);
return $value === false ? $default : $value;
}
function getRequiredEnv(string $name): string
{
$value = getenv($name);
if ($value === false) {
echo 'Missing environment variable: ', $name, PHP_EOL;
exit(1);
}
return $value;
}
(function (): void {
require 'vendor/autoload.php';
$engine = getOptionalEnv('ENGINE');
if ($engine === null) {
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, geosop', PHP_EOL;
} else {
switch ($engine) {
case 'pdo_mysql':
$emulatePrepares = getOptionalEnv('EMULATE_PREPARES') === 'ON';
echo 'Using PdoEngine for MySQL', PHP_EOL;
echo 'with emulated prepares ', ($emulatePrepares ? 'ON' : 'OFF'), PHP_EOL;
$host = getRequiredEnv('MYSQL_HOST');
$port = getOptionalEnvOrDefault('MYSQL_PORT', '3306');
$username = getRequiredEnv('MYSQL_USER');
$password = getRequiredEnv('MYSQL_PASSWORD');
$pdo = new PDO(
sprintf('mysql:host=%s;port=%d', $host, $port),
$username,
$password,
);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulatePrepares);
$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;
$host = getRequiredEnv('POSTGRES_HOST');
$port = getOptionalEnvOrDefault('POSTGRES_PORT', '5432');
$username = getRequiredEnv('POSTGRES_USER');
$password = getRequiredEnv('POSTGRES_PASSWORD');
$pdo = new PDO(
sprintf('pgsql:host=%s;port=%d', $host, $port),
$username,
$password,
);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('CREATE EXTENSION IF NOT EXISTS postgis;');
$statement = $pdo->query('SELECT version()');
$version = $statement->fetchColumn();
echo 'PostgreSQL version: ', $version, PHP_EOL;
$statement = $pdo->query('SELECT PostGIS_Full_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;
$sqlite3->exec('SELECT InitSpatialMetaData()');
$engine = new Sqlite3Engine($sqlite3);
break;
case 'geos':
echo 'Using GeosEngine', PHP_EOL;
echo 'GEOS version: ', GEOSVersion(), PHP_EOL;
$engine = new GeosEngine();
break;
case 'geosop':
echo 'Using GeosOpEngine', PHP_EOL;
$geosopPath = getRequiredEnv('GEOSOP_PATH');
$engine = new GeosOpEngine($geosopPath);
echo 'geosop version: ', $engine->getGeosOpVersion(), PHP_EOL;
break;
default:
echo 'Unknown engine: ', $engine, PHP_EOL;
exit(1);
}
$GLOBALS['GEOMETRY_ENGINE'] = $engine;
}
})();