Use abstract test class to avoid code duplications in tests

This commit is contained in:
Madhura Jayaratne 2011-08-13 10:10:32 +05:30
parent d6bf1cd451
commit 9ed1cd7c3e
7 changed files with 115 additions and 296 deletions

View File

@ -0,0 +1,60 @@
<?php
/**
* Abstract parent class for all PMA_GIS_<Geom_type> test classes
*
* @package phpMyAdmin-test
*/
require_once 'libraries/gis/pma_gis_geometry.php';
/**
* Abstract parent class for all PMA_GIS_<Geom_type> test classes
*/
abstract class PMA_GIS_GeometryTest extends PHPUnit_Framework_TestCase
{
/**
* test generateWkt method
*
* @param array $gis_data array of GIS data
* @param int $index index
* @param string $empty string to be insterted in place of missing values
* @param string $wkt expected WKT
*
* @return nothing
* @dataProvider providerForTestGenerateWkt
*/
public function testGenerateWkt($gis_data, $index, $empty, $wkt)
{
if ($empty == null) {
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
} else {
$this->assertEquals(
$this->object->generateWkt($gis_data, $index, $empty),
$wkt
);
}
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param index $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == null) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
}
?>

View File

@ -5,13 +5,14 @@
* @package phpMyAdmin-test
*/
require_once 'PMA_GIS_Geometry_test.php';
require_once 'libraries/gis/pma_gis_geometry.php';
require_once 'libraries/gis/pma_gis_linestring.php';
/**
* Tests for PMA_GIS_Linestring class
*/
class PMA_GIS_LinestringTest extends PHPUnit_Framework_TestCase
class PMA_GIS_LinestringTest extends PMA_GIS_GeometryTest
{
/**
* @var PMA_GIS_Linestring
@ -43,29 +44,6 @@ class PMA_GIS_LinestringTest extends PHPUnit_Framework_TestCase
unset($this->object);
}
/**
* test generateWkt method
*
* @param array $gis_data array of GIS data
* @param int $index index
* @param string $empty string to be insterted in place of missing values
* @param string $wkt expected WKT
*
* @return nothing
* @dataProvider providerForTestGenerateWkt
*/
public function testGenerateWkt($gis_data, $index, $empty, $wkt)
{
if ($empty == null) {
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
} else {
$this->assertEquals(
$this->object->generateWkt($gis_data, $index, $empty),
$wkt
);
}
}
/**
* data provider for testGenerateWkt
*
@ -75,10 +53,10 @@ class PMA_GIS_LinestringTest extends PHPUnit_Framework_TestCase
{
$temp1 = array(
0 => array(
'LINESTRING' => array(
'LINESTRING' => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
)
)
);
@ -125,28 +103,6 @@ class PMA_GIS_LinestringTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param index $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == 0) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
/**
* data provider for testGenerateParams
*
@ -167,7 +123,7 @@ class PMA_GIS_LinestringTest extends PHPUnit_Framework_TestCase
return array(
array(
"'LINESTRING(5.02 8.45,6.14 0.15)',124",
0,
null,
array(
'srid' => '124',
0 => $temp

View File

@ -5,15 +5,16 @@
* @package phpMyAdmin-test
*/
require_once 'PMA_GIS_Geometry_test.php';
require_once 'libraries/gis/pma_gis_geometry.php';
require_once 'libraries/gis/pma_gis_multilinestring.php';
/**
* Tests for PMA_GIS_Multilinestring class
*/
class PMA_GIS_MultilinestringTest extends PHPUnit_Framework_TestCase
class PMA_GIS_MultilinestringTest extends PMA_GIS_GeometryTest
{
/**
/**
* @var PMA_GIS_Multilinestring
* @access protected
*/
@ -43,29 +44,6 @@ class PMA_GIS_MultilinestringTest extends PHPUnit_Framework_TestCase
unset($this->object);
}
/**
* test generateWkt method
*
* @param array $gis_data array of GIS data
* @param int $index index
* @param string $empty string to be insterted in place of missing values
* @param string $wkt expected WKT
*
* @return nothing
* @dataProvider providerForTestGenerateWkt
*/
public function testGenerateWkt($gis_data, $index, $empty, $wkt)
{
if ($empty == null) {
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
} else {
$this->assertEquals(
$this->object->generateWkt($gis_data, $index, $empty),
$wkt
);
}
}
/**
* data provider for testGenerateWkt
*
@ -75,18 +53,18 @@ class PMA_GIS_MultilinestringTest extends PHPUnit_Framework_TestCase
{
$temp = array(
0 => array(
'MULTILINESTRING' => array(
'MULTILINESTRING' => array(
'no_of_lines' => 2,
0 => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
),
1 => array(
'no_of_points' => 2,
0 => array('x' => 1.23, 'y' => 4.25),
1 => array('x' => 9.15, 'y' => 0.47)
)
0 => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
),
1 => array(
'no_of_points' => 2,
0 => array('x' => 1.23, 'y' => 4.25),
1 => array('x' => 9.15, 'y' => 0.47)
)
)
)
);
@ -156,28 +134,6 @@ class PMA_GIS_MultilinestringTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param index $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == null) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
/**
* data provider for testGenerateParams
*

View File

@ -5,13 +5,14 @@
* @package phpMyAdmin-test
*/
require_once 'PMA_GIS_Geometry_test.php';
require_once 'libraries/gis/pma_gis_geometry.php';
require_once 'libraries/gis/pma_gis_multipoint.php';
/**
* Tests for PMA_GIS_Multipoint class
*/
class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
class PMA_GIS_MultipointTest extends PMA_GIS_GeometryTest
{
/**
* @var PMA_GIS_Multipoint
@ -43,21 +44,6 @@ class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
unset($this->object);
}
/**
* test generateWkt method
*
* @param array $gis_data array of GIS data
* @param int $index index
* @param string $wkt expected WKT
*
* @dataProvider providerForTestGenerateWkt
* @return nothing
*/
public function testGenerateWkt($gis_data, $index, $wkt)
{
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
}
/**
* data provider for testGenerateWkt
*
@ -67,15 +53,15 @@ class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
{
$gis_data1 = array(
0 => array(
'MULTIPOINT' => array(
'MULTIPOINT' => array(
'no_of_points' => 2,
0 => array(
'x' => 5.02,
'y' => 8.45
0 => array(
'x' => 5.02,
'y' => 8.45
),
1 => array(
'x' => 1.56,
'y' => 4.36
'x' => 1.56,
'y' => 4.36
)
)
)
@ -88,11 +74,13 @@ class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
array(
$gis_data1,
0,
null,
'MULTIPOINT(5.02 8.45,1.56 4.36)'
),
array(
$gis_data2,
0,
null,
'MULTIPOINT(5.02 8.45)'
)
);
@ -106,7 +94,7 @@ class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
public function testGetShape()
{
$gis_data = array(
'numpoints' => 2,
'numpoints' => 2,
'points' => array(
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
@ -119,28 +107,6 @@ class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param index $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == 0) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
/**
* data provider for testGenerateParams
*
@ -161,7 +127,7 @@ class PMA_GIS_MultipointTest extends PHPUnit_Framework_TestCase
return array(
array(
"'MULTIPOINT(5.02 8.45,6.14 0.15)',124",
0,
null,
array(
'srid' => '124',
0 => $temp1

View File

@ -5,13 +5,14 @@
* @package phpMyAdmin-test
*/
require_once 'PMA_GIS_Geometry_test.php';
require_once 'libraries/gis/pma_gis_geometry.php';
require_once 'libraries/gis/pma_gis_multipolygon.php';
/**
* Tests for PMA_GIS_Multipolygon class
*/
class PMA_GIS_MultipolygonTest extends PHPUnit_Framework_TestCase
class PMA_GIS_MultipolygonTest extends PMA_GIS_GeometryTest
{
/**
* @var PMA_GIS_Multipolygon
@ -80,29 +81,6 @@ class PMA_GIS_MultipolygonTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateWkt method
*
* @param array $gis_data array of GIS data
* @param int $index index
* @param string $empty string to be insterted in place of missing values
* @param string $wkt expected WKT
*
* @return nothing
* @dataProvider providerForTestGenerateWkt
*/
public function testGenerateWkt($gis_data, $index, $empty, $wkt)
{
if ($empty == null) {
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
} else {
$this->assertEquals(
$this->object->generateWkt($gis_data, $index, $empty),
$wkt
);
}
}
/**
* data provider for testGenerateWkt
*
@ -125,28 +103,6 @@ class PMA_GIS_MultipolygonTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param index $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == null) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
/**
* data provider for testGenerateParams
*

View File

@ -5,13 +5,14 @@
* @package phpMyAdmin-test
*/
require_once 'PMA_GIS_Geometry_test.php';
require_once 'libraries/gis/pma_gis_geometry.php';
require_once 'libraries/gis/pma_gis_point.php';
/**
* Tests for PMA_GIS_Point class.
*/
class PMA_GIS_PointTest extends PHPUnit_Framework_TestCase
class PMA_GIS_PointTest extends PMA_GIS_GeometryTest
{
/**
* @var PMA_GIS_Point
@ -43,21 +44,6 @@ class PMA_GIS_PointTest extends PHPUnit_Framework_TestCase
unset($this->object);
}
/**
* test generateWkt method
*
* @param array $gis_data array containing the GIS data
* @param int $index index to the array
* @param string $wkt expected Well Known Text
*
* @dataProvider providerForTestGenerateWkt
* @return nothing
*/
public function testGenerateWkt($gis_data, $index, $wkt)
{
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
}
/**
* data provider for testGenerateWkt
*
@ -69,26 +55,31 @@ class PMA_GIS_PointTest extends PHPUnit_Framework_TestCase
array(
array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
0,
null,
'POINT(5.02 8.45)'
),
array(
array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
1,
null,
'POINT( )'
),
array(
array(0 => array('POINT' => array('x' => 5.02))),
0,
null,
'POINT(5.02 )'
),
array(
array(0 => array('POINT' => array('y' => 8.45))),
0,
null,
'POINT( 8.45)'
),
array(
array(0 => array('POINT' => array())),
0,
null,
'POINT( )'
),
);
@ -123,28 +114,6 @@ class PMA_GIS_PointTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param array $params expected output array
* @param index $index index
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $params, $index)
{
if ($index == 0) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
/**
* data provider for testGenerateParams
*
@ -155,23 +124,23 @@ class PMA_GIS_PointTest extends PHPUnit_Framework_TestCase
return array(
array(
"'POINT(5.02 8.45)',124",
null,
array(
'srid' => '124',
0 => array(
'POINT' => array('x' => '5.02', 'y' => '8.45')
),
),
0
),
array(
'POINT(5.02 8.45)',
array(
2 => array(
'gis_type' => 'POINT',
'POINT' => array('x' => '5.02', 'y' => '8.45')
),
),
2
)
),
array(
'POINT(5.02 8.45)',
2,
array(
2 => array(
'gis_type' => 'POINT',
'POINT' => array('x' => '5.02', 'y' => '8.45')
),
)
)
);
}

View File

@ -5,13 +5,14 @@
* @package phpMyAdmin-test
*/
require_once 'PMA_GIS_Geometry_test.php';
require_once 'libraries/gis/pma_gis_geometry.php';
require_once 'libraries/gis/pma_gis_polygon.php';
/**
* Tests for PMA_GIS_Polygon class
*/
class PMA_GIS_PolygonTest extends PHPUnit_Framework_TestCase
class PMA_GIS_PolygonTest extends PMA_GIS_GeometryTest
{
/**
* @var PMA_GIS_Polygon
@ -67,29 +68,6 @@ class PMA_GIS_PolygonTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateWkt method
*
* @param array $gis_data array of GIS data
* @param int $index index
* @param string $empty string to be insterted in place of missing values
* @param string $wkt expected WKT
*
* @return nothing
* @dataProvider providerForTestGenerateWkt
*/
public function testGenerateWkt($gis_data, $index, $empty, $wkt)
{
if ($empty == null) {
$this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
} else {
$this->assertEquals(
$this->object->generateWkt($gis_data, $index, $empty),
$wkt
);
}
}
/**
* data provider for testGenerateWkt
*
@ -135,28 +113,6 @@ class PMA_GIS_PolygonTest extends PHPUnit_Framework_TestCase
);
}
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param index $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return nothing
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == null) {
$this->assertEquals($this->object->generateParams($wkt), $params);
} else {
$this->assertEquals(
$this->object->generateParams($wkt, $index),
$params
);
}
}
/**
* data provider for testGenerateParams
*