Skip to content

Commit 8244e5e

Browse files
committed
Refactor tests to be object oriented.
1 parent 80f9973 commit 8244e5e

File tree

12 files changed

+336
-194
lines changed

12 files changed

+336
-194
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tests/*/*.php
4545
tests/*/*.exp
4646
tests/*/*.log
4747
tests/*/*.sh
48-
!tests/test_case.php
48+
!tests/util/*
4949
!tests/data/*
5050

5151
### Composer

header_graphic.png

4.41 KB
Loading

tests/agg_renderer.phpt

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,46 @@
55
--FILE--
66
<?php
77

8-
// Setup
9-
$configOutput = [];
10-
exec('mapnik-config --input-plugins', $configOutput);
11-
\Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
12-
$map = new \Mapnik\Map(640, 480);
13-
$basePath = realpath(dirname(__FILE__) . '/data');
14-
$map->loadXmlFile($basePath . '/world.xml', false, $basePath);
15-
$map->zoomAll();
16-
$image = new \Mapnik\Image(640, 480);
17-
18-
// Assert AggRenderer instantiation
19-
$renderer = new \Mapnik\AggRenderer($map, $image);
20-
print ($renderer instanceof \Mapnik\AggRenderer);
21-
22-
// Assert apply() successful
23-
print $renderer->apply();
8+
require_once('util/test_case.php');
9+
10+
class AggRendererTest extends MapnikTestCase
11+
{
12+
private $basePath;
13+
14+
private $exampleMap;
15+
16+
public function setup()
17+
{
18+
$configOutput = [];
19+
exec('mapnik-config --input-plugins', $configOutput);
20+
\Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
21+
22+
$this->basePath = realpath(__DIR__ . '/data');
23+
24+
$this->exampleMap = new \Mapnik\Map(640, 480);
25+
$this->exampleMap->loadXmlFile($this->basePath . "/world.xml", false, $this->basePath);
26+
$this->exampleMap->zoomAll();
27+
}
28+
29+
30+
public function testConstructor()
31+
{
32+
$image = new \Mapnik\Image(640, 480);
33+
$renderer = new \Mapnik\AggRenderer($this->exampleMap, $image);
34+
35+
assert('$renderer instanceof \Mapnik\AggRenderer', 'Instantiating \Mapnik\AggRenderer failed.');
36+
}
37+
38+
public function testApply()
39+
{
40+
$image = new \Mapnik\Image(640, 480);
41+
$renderer = new \Mapnik\AggRenderer($this->exampleMap, $image);
42+
43+
assert('$renderer->apply() === true', 'AggRenderer->apply() failed.');
44+
}
45+
}
46+
47+
new AggRendererTest();
2448

2549
?>
26-
--EXPECT--
27-
11
50+
--EXPECT--

tests/box2d.phpt

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,42 @@
55
--FILE--
66
<?php
77

8-
// Assert Box2D instantiation
9-
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
10-
print ($box2d instanceof \Mapnik\Box2D);
8+
require_once('util/test_case.php');
9+
10+
class Box2DTest extends MapnikTestCase
11+
{
12+
public function testConstructor()
13+
{
14+
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
15+
assert('$box2d instanceof \Mapnik\Box2D', 'Instantiating \Mapnik\Box2D failed.');
16+
}
17+
18+
public function testMinX()
19+
{
20+
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
21+
assert('$box2d->minX() === -180.0', 'Box2D->minX() failed.');
22+
}
23+
24+
public function testMinY()
25+
{
26+
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
27+
assert('$box2d->minY() === -90.0', 'Box2D->minY() failed.');
28+
}
29+
30+
public function testMaxX()
31+
{
32+
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
33+
assert('$box2d->maxX() === 180.0', 'Box2D->maxX() failed.');
34+
}
35+
36+
public function testMaxY()
37+
{
38+
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
39+
assert('$box2d->maxY() === 90.0', 'Box2D->maxY() failed.');
40+
}
41+
}
42+
43+
new Box2DTest();
1144

1245
?>
13-
--EXPECT--
14-
1
46+
--EXPECT--

tests/data/header_graphic.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<Map background-color="darkslateblue" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
2-
<!--
32
<Style name="title_style">
43
<Rule>
54
<TextSymbolizer
@@ -13,7 +12,6 @@
1312
</TextSymbolizer>
1413
</Rule>
1514
</Style>
16-
-->
1715
<Style name="world_style">
1816
<Rule>
1917
<PolygonSymbolizer fill="slateblue" />
@@ -28,15 +26,11 @@
2826
<Parameter name="file">ne_110m_admin_0_countries.shp</Parameter>
2927
</Datasource>
3028
</Layer>
31-
<!--
32-
Boost dependency on Ubuntu Trusty (Travis CI) is below required version for CSV input plugin.
33-
3429
<Layer name="title" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
3530
<StyleName>title_style</StyleName>
3631
<Datasource>
3732
<Parameter name="type">csv</Parameter>
3833
<Parameter name="file">header_graphic.csv</Parameter>
3934
</Datasource>
4035
</Layer>
41-
-->
4236
</Map>

tests/datasource_cache.phpt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
--FILE--
66
<?php
77

8-
// Assert no plugins registered at start
9-
$plugins = \Mapnik\DatasourceCache::getPluginNames();
10-
print (count($plugins) === 0);
8+
require_once('util/test_case.php');
119

12-
// Assert successful registration of datasource plugins
13-
$configOutput = [];
14-
exec('mapnik-config --input-plugins', $configOutput);
15-
print \Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
10+
class DatasourceCacheTest extends MapnikTestCase
11+
{
12+
public function testGetPluginNamesEmpty()
13+
{
14+
$plugins = \Mapnik\DatasourceCache::getPluginNames();
15+
assert('count($plugins) === 0', 'DatasourceCache cache plugins not empty even though register was not called.');
16+
}
1617

17-
// Assert that we have plugins now
18-
$plugins = \Mapnik\DatasourceCache::getPluginNames();
19-
print (count($plugins) > 0);
18+
public function testRegisterDatasources()
19+
{
20+
$configOutput = [];
21+
exec('mapnik-config --input-plugins', $configOutput);
22+
\Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
23+
$plugins = \Mapnik\DatasourceCache::getPluginNames();
24+
25+
assert('count($plugins) > 0', 'No plugins after registering directory with DatasourceCache.');
26+
}
27+
}
28+
29+
new DatasourceCacheTest();
2030

2131
?>
22-
--EXPECT--
23-
111
32+
--EXPECT--

tests/header_graphic.phpt

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,44 @@ Header Graphic
77

88
// Just a fun test to give the project a header graphic...
99

10-
$pluginConfigOutput = [];
11-
exec('mapnik-config --input-plugins', $pluginConfigOutput);
12-
\Mapnik\DatasourceCache::registerDatasources($pluginConfigOutput[0]);
10+
require_once('util/test_case.php');
1311

14-
$map = new \Mapnik\Map(1280, 320);
12+
class HeaderGraphicTest extends MapnikTestCase
13+
{
14+
public function testMakeHeaderGraphic()
15+
{
16+
$pluginConfigOutput = [];
17+
exec('mapnik-config --input-plugins', $pluginConfigOutput);
18+
\Mapnik\DatasourceCache::registerDatasources($pluginConfigOutput[0]);
1519

16-
$fontConfigOutput = [];
17-
exec('mapnik-config --fonts', $fontConfigOutput);
18-
$map->registerFonts($fontConfigOutput[0]);
20+
// Travis build machine does not have CSV plugin due to incompatible Boost version.
21+
// Just return early if CSV isn't available.
22+
if (!in_array('csv', \Mapnik\DatasourceCache::getPluginNames())) return;
1923

20-
$basePath = realpath(dirname(__FILE__) . '/data');
21-
$map->loadXmlFile($basePath . '/header_graphic.xml', false, $basePath);
24+
$map = new \Mapnik\Map(1280, 320);
2225

23-
$box = new \Mapnik\Box2D(-134, -25, 174, 67);
24-
$map->zoomToBox($box);
26+
$fontConfigOutput = [];
27+
exec('mapnik-config --fonts', $fontConfigOutput);
28+
$map->registerFonts($fontConfigOutput[0]);
2529

26-
$image = new \Mapnik\Image(1280, 320);
27-
$renderer = new \Mapnik\AggRenderer($map, $image);
28-
$renderer->apply();
30+
$basePath = realpath(__DIR__ . '/data');
31+
$map->loadXmlFile($basePath . '/header_graphic.xml', false, $basePath);
2932

30-
$imageFile = realpath(dirname(__FILE__) . '/../') . '/header_graphic.png';
31-
$image->saveToFile($imageFile);
32-
print file_exists($imageFile);
33+
$box = new \Mapnik\Box2D(-134, -25, 174, 67);
34+
$map->zoomToBox($box);
35+
36+
$image = new \Mapnik\Image(1280, 320);
37+
$renderer = new \Mapnik\AggRenderer($map, $image);
38+
$renderer->apply();
39+
40+
$imageFile = realpath(__DIR__ . '/../') . '/header_graphic.png';
41+
$image->saveToFile($imageFile);
42+
43+
assert('file_exists($imageFile) === true', 'Header graphic does not exist.');
44+
}
45+
}
46+
47+
new HeaderGraphicTest();
3348

3449
?>
35-
--EXPECT--
36-
1
50+
--EXPECT--

0 commit comments

Comments
 (0)