Skip to content

Commit

Permalink
Migrate to PHPUnit attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Jan 23, 2024
1 parent 2a07f33 commit 423c391
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 301 deletions.
29 changes: 9 additions & 20 deletions tests/CircularStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
use Brick\Geo\Exception\InvalidGeometryException;
use Brick\Geo\Exception\NoSuchGeometryException;
use Brick\Geo\Point;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class CircularString.
*/
class CircularStringTest extends AbstractTestCase
{
/**
* @dataProvider providerCreate
*
* @param string[] $pointsWKT The WKT of the Points that compose the CircularString.
* @param bool $is3D Whether the points have Z coordinates.
* @param bool $isMeasured Whether the points have M coordinates.
* @param string $circularStringWKT The WKT of the expected CircularString.
*/
#[DataProvider('providerCreate')]
public function testCreate(array $pointsWKT, bool $is3D, bool $isMeasured, string $circularStringWKT) : void
{
foreach ([0, 1] as $srid) {
Expand All @@ -46,10 +46,9 @@ public static function providerCreate() : array
}

/**
* @dataProvider providerCreateInvalidCircularString
*
* @param string $circularString The WKT of an invalid CircularString.
*/
#[DataProvider('providerCreateInvalidCircularString')]
public function testCreateInvalidCircularString(string $circularString) : void
{
$this->expectException(InvalidGeometryException::class);
Expand All @@ -66,9 +65,7 @@ public static function providerCreateInvalidCircularString() : array
];
}

/**
* @dataProvider providerStartPointEndPoint
*/
#[DataProvider('providerStartPointEndPoint')]
public function testStartPointEndPoint(string $circularString, string $startPoint, string $endPoint) : void
{
foreach ([0, 1] as $srid) {
Expand All @@ -89,21 +86,19 @@ public static function providerStartPointEndPoint() : array
}

/**
* @dataProvider providerEmptyCircularString
*
* @param string $circularString The WKT of an empty CircularString.
*/
#[DataProvider('providerEmptyCircularString')]
public function testStartPointOfEmptyCircularString(string $circularString) : void
{
$this->expectException(EmptyGeometryException::class);
CircularString::fromText($circularString)->startPoint();
}

/**
* @dataProvider providerEmptyCircularString
*
* @param string $circularString The WKT of an empty CircularString.
*/
#[DataProvider('providerEmptyCircularString')]
public function testEndPointOfEmptyCircularString(string $circularString) : void
{
$this->expectException(EmptyGeometryException::class);
Expand All @@ -120,9 +115,7 @@ public static function providerEmptyCircularString() : array
];
}

/**
* @dataProvider providerNumPoints
*/
#[DataProvider('providerNumPoints')]
public function testNumPoints(string $circularString, int $numPoints) : void
{
$circularString = CircularString::fromText($circularString);
Expand All @@ -143,9 +136,7 @@ public static function providerNumPoints() : array
];
}

/**
* @dataProvider providerPointN
*/
#[DataProvider('providerPointN')]
public function testPointN(string $lineString, int $n, string $pointN) : void
{
foreach ([0, 1] as $srid) {
Expand All @@ -172,9 +163,7 @@ public static function providerPointN() : array
];
}

/**
* @dataProvider providerInvalidPointNThrowsException
*/
#[DataProvider('providerInvalidPointNThrowsException')]
public function testInvalidPointNThrowsException(string $lineString, int $n) : void
{
$this->expectException(NoSuchGeometryException::class);
Expand Down
23 changes: 8 additions & 15 deletions tests/CompoundCurveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
use Brick\Geo\Exception\EmptyGeometryException;
use Brick\Geo\Exception\InvalidGeometryException;
use Brick\Geo\Exception\NoSuchGeometryException;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class CompoundCurve.
*/
class CompoundCurveTest extends AbstractTestCase
{
/**
* @dataProvider providerCreate
*
* @param string[] $curvesWKT The WKT of the Curves that compose the CompoundCurve.
* @param bool $is3D Whether the curves have Z coordinates.
* @param bool $isMeasured Whether the curves have M coordinates.
* @param string $compoundCurveWKT The WKT of the expected CompoundCurve.
*/
#[DataProvider('providerCreate')]
public function testCreate(array $curvesWKT, bool $is3D, bool $isMeasured, string $compoundCurveWKT) : void
{
foreach ([0, 1] as $srid) {
Expand All @@ -46,10 +46,9 @@ public static function providerCreate() : array
}

/**
* @dataProvider providerCreateInvalidCompoundCurve
*
* @param string $compoundCurve The WKT of an invalid CompoundCurve.
*/
#[DataProvider('providerCreateInvalidCompoundCurve')]
public function testCreateInvalidCompoundCurve(string $compoundCurve) : void
{
$this->expectException(InvalidGeometryException::class);
Expand All @@ -65,9 +64,7 @@ public static function providerCreateInvalidCompoundCurve() : array
];
}

/**
* @dataProvider providerStartPointEndPoint
*/
#[DataProvider('providerStartPointEndPoint')]
public function testStartPointEndPoint(string $compoundCurve, string $startPoint, string $endPoint) : void
{
foreach ([0, 1] as $srid) {
Expand All @@ -88,21 +85,19 @@ public static function providerStartPointEndPoint() : array
}

/**
* @dataProvider providerEmptyCompoundCurve
*
* @param string $compoundCurve The WKT of an empty CompoundCurve.
*/
#[DataProvider('providerEmptyCompoundCurve')]
public function testStartPointOfEmptyCompoundCurve(string $compoundCurve) : void
{
$this->expectException(EmptyGeometryException::class);
CompoundCurve::fromText($compoundCurve)->startPoint();
}

/**
* @dataProvider providerEmptyCompoundCurve
*
* @param string $compoundCurve The WKT of an empty CompoundCurve.
*/
#[DataProvider('providerEmptyCompoundCurve')]
public function testEndPointOfEmptyCompoundCurve(string $compoundCurve) : void
{
$this->expectException(EmptyGeometryException::class);
Expand All @@ -120,11 +115,10 @@ public static function providerEmptyCompoundCurve() : array
}

/**
* @dataProvider providerNumCurves
*
* @param string $compoundCurve The WKT of the CompoundCurve to test.
* @param int $numCurves The expected number of curves.
*/
#[DataProvider('providerNumCurves')]
public function testNumCurves(string $compoundCurve, int $numCurves) : void
{
self::assertSame($numCurves, CompoundCurve::fromText($compoundCurve)->numCurves());
Expand All @@ -145,13 +139,12 @@ public static function providerNumCurves() : array
}

/**
* @dataProvider providerCurveN
*
* @param string $compoundCurve The WKT of the CompoundCurve to test.
* @param int $n The curve number.
* @param string|null $curveN The WKT of the expected curve, or NULL if an exception is expected.
* @param int $srid The SRID of the geometries.
*/
#[DataProvider('providerCurveN')]
public function testCurveN(string $compoundCurve, int $n, ?string $curveN, int $srid) : void
{
if ($curveN === null) {
Expand Down
17 changes: 6 additions & 11 deletions tests/CurvePolygonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
use Brick\Geo\CurvePolygon;
use Brick\Geo\Exception\EmptyGeometryException;
use Brick\Geo\Exception\NoSuchGeometryException;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class CurvePolygon.
*/
class CurvePolygonTest extends AbstractTestCase
{
/**
* @dataProvider providerEmptyFactoryMethod
*/
#[DataProvider('providerEmptyFactoryMethod')]
public function testEmptyFactoryMethod(bool $is3D, bool $isMeasured, int $srid) : void
{
$cs = new CoordinateSystem($is3D, $isMeasured, $srid);
Expand All @@ -43,11 +42,10 @@ public static function providerEmptyFactoryMethod() : array
}

/**
* @dataProvider providerExteriorRing
*
* @param string $curvePolygon The WKT of the CurvePolygon to test.
* @param string $exteriorRing The WKT of the expected exterior ring.
*/
#[DataProvider('providerExteriorRing')]
public function testExteriorRing(string $curvePolygon, string $exteriorRing) : void
{
foreach ([0, 1] as $srid) {
Expand All @@ -67,10 +65,9 @@ public static function providerExteriorRing() : array
}

/**
* @dataProvider providerExteriorRingOfEmptyCurvePolygon
*
* @param string $polygon The WKT of the CurvePolygon to test.
*/
#[DataProvider('providerExteriorRingOfEmptyCurvePolygon')]
public function testExteriorRingOfEmptyCurvePolygon(string $polygon) : void
{
$this->expectException(EmptyGeometryException::class);
Expand All @@ -87,11 +84,10 @@ public static function providerExteriorRingOfEmptyCurvePolygon() : array
];
}
/**
* @dataProvider providerNumInteriorRings
*
* @param string $polygon The WKT of the Polygon to test.
* @param int $numInteriorRings The expected number of interior rings.
*/
#[DataProvider('providerNumInteriorRings')]
public function testNumInteriorRings(string $polygon, int $numInteriorRings) : void
{
$polygon = CurvePolygon::fromText($polygon);
Expand All @@ -114,13 +110,12 @@ public static function providerNumInteriorRings() : array
}

/**
* @dataProvider providerInteriorRingN
*
* @param string $curvePolygon The WKT of the CurvePolygon to test.
* @param int $n The ring number.
* @param string|null $interiorRingN The WKT of the expected interior ring, or NULL if an exception is expected.
* @param int $srid The SRID of the geometries.
*/
#[DataProvider('providerInteriorRingN')]
public function testInteriorRingN(string $curvePolygon, int $n, ?string $interiorRingN, int $srid) : void
{
if ($interiorRingN === null) {
Expand Down
12 changes: 4 additions & 8 deletions tests/CurveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

use Brick\Geo\Curve;
use Brick\Geo\Exception\EmptyGeometryException;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class Curve.
*/
class CurveTest extends AbstractTestCase
{
/**
* @dataProvider providerStartPointEndPoint
*
* @param string $lineString The WKT of the Curve to test.
* @param string $startPoint The WKT of the expected start point.
* @param string $endPoint The WKT of the expected end point.
*/
#[DataProvider('providerStartPointEndPoint')]
public function testStartPointEndPoint(string $lineString, string $startPoint, string $endPoint) : void
{
foreach ([0, 1] as $srid) {
Expand Down Expand Up @@ -49,18 +49,14 @@ public static function providerStartPointEndPoint() : array
];
}

/**
* @dataProvider providerEmptyCurve
*/
#[DataProvider('providerEmptyCurve')]
public function testStartPointOfEmptyCurveThrowsException(string $lineString) : void
{
$this->expectException(EmptyGeometryException::class);
Curve::fromText($lineString)->startPoint();
}

/**
* @dataProvider providerEmptyCurve
*/
#[DataProvider('providerEmptyCurve')]
public function testEndPointOfEmptyCurveThrowsException(string $lineString) : void
{
$this->expectException(EmptyGeometryException::class);
Expand Down
7 changes: 3 additions & 4 deletions tests/GeometryCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use Brick\Geo\GeometryCollection;
use Brick\Geo\LineString;
use Brick\Geo\Point;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class GeometryCollection.
*/
class GeometryCollectionTest extends AbstractTestCase
{
/**
* @dataProvider providerNumGeometries
*
* @param string $geometry The WKT of the GeometryCollection to test.
* @param int $numGeometries The expected number of geometries.
*/
#[DataProvider('providerNumGeometries')]
public function testNumGeometries(string $geometry, int $numGeometries) : void
{
$geometry = GeometryCollection::fromText($geometry);
Expand All @@ -36,13 +36,12 @@ public static function providerNumGeometries() : array
}

/**
* @dataProvider providerGeometryN
*
* @param string $geometry The WKT of the GeometryCollection to test.
* @param int $n The number of the geometry to return.
* @param string|null $geometryN The WKT of the expected result, or NULL if an exception is expected.
* @param int $srid The SRID of the geometries.
*/
#[DataProvider('providerGeometryN')]
public function testGeometryN(string $geometry, int $n, ?string $geometryN, int $srid) : void
{
if ($geometryN === null) {
Expand Down
Loading

0 comments on commit 423c391

Please sign in to comment.