diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ccc5a91..d8ea982 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,14 +12,15 @@ jobs: strategy: matrix: php: - - "7.4" - - "8.0" - "8.1" - "8.2" + - "8.3" + - "8.4" + - "8.5" dependency-versions: - "highest" include: - - php: "7.4" + - php: "8.1" dependency-versions: "lowest" steps: diff --git a/composer.json b/composer.json index cd0aa70..596a6be 100644 --- a/composer.json +++ b/composer.json @@ -9,12 +9,11 @@ { "name": "Jeremy Mikola", "email": "jmikola@gmail.com" } ], "require": { - "php": "^7.4 || ^8.0", - "ext-json": "*", - "symfony/polyfill-php80": "^1.25" + "php": "^8.1", + "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^10", "scrutinizer/ocular": "^1.8.1", "squizlabs/php_codesniffer": "^3.6", "slevomat/coding-standard": "^8.0" diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2bdffd6..9afa013 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -118,15 +118,6 @@ - - - - - - - - - @@ -160,7 +151,6 @@ - diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0f506df..e914ca0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,4 @@ - ./tests/ - - + - ./src/ + ./src/ - + diff --git a/src/CoordinateReferenceSystem/CoordinateReferenceSystem.php b/src/CoordinateReferenceSystem/CoordinateReferenceSystem.php index 2633c91..e62b684 100644 --- a/src/CoordinateReferenceSystem/CoordinateReferenceSystem.php +++ b/src/CoordinateReferenceSystem/CoordinateReferenceSystem.php @@ -76,15 +76,11 @@ final public static function jsonUnserialize($json): self $type = (string) $json['type']; $properties = $json['properties']; - switch ($type) { - case 'link': - return Linked::jsonUnserializeFromProperties($properties); - - case 'name': - return Named::jsonUnserializeFromProperties($properties); - } - - throw UnserializationException::unsupportedType('CRS', $type); + return match ($type) { + 'link' => Linked::jsonUnserializeFromProperties($properties), + 'name' => Named::jsonUnserializeFromProperties($properties), + default => throw UnserializationException::unsupportedType('CRS', $type), + }; } /** diff --git a/src/Exception/UnserializationException.php b/src/Exception/UnserializationException.php index 7b9607a..2ff0c2c 100644 --- a/src/Exception/UnserializationException.php +++ b/src/Exception/UnserializationException.php @@ -41,7 +41,7 @@ public static function invalidProperty(string $context, string $property, $value $context, $property, $expectedType, - is_object($value) ? get_class($value) : gettype($value) + get_debug_type($value) )); } diff --git a/src/GeoJson.php b/src/GeoJson.php index 5f82dcb..f384d65 100644 --- a/src/GeoJson.php +++ b/src/GeoJson.php @@ -143,7 +143,7 @@ final public static function jsonUnserialize($json): self throw UnserializationException::invalidProperty($type, 'features', $json['features'], 'array'); } - $args[] = array_map([self::class, 'jsonUnserialize'], $json['features']); + $args[] = array_map(self::jsonUnserialize(...), $json['features']); break; case self::TYPE_GEOMETRY_COLLECTION: @@ -155,7 +155,7 @@ final public static function jsonUnserialize($json): self throw UnserializationException::invalidProperty($type, 'geometries', $json['geometries'], 'array'); } - $args[] = array_map([self::class, 'jsonUnserialize'], $json['geometries']); + $args[] = array_map(self::jsonUnserialize(...), $json['geometries']); break; default: diff --git a/tests/BoundingBoxTest.php b/tests/BoundingBoxTest.php index 00d892f..951ea21 100644 --- a/tests/BoundingBoxTest.php +++ b/tests/BoundingBoxTest.php @@ -8,10 +8,11 @@ use GeoJson\Exception\InvalidArgumentException; use GeoJson\Exception\UnserializationException; use GeoJson\JsonUnserializable; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use stdClass; -use function func_get_args; use function json_decode; class BoundingBoxTest extends TestCase @@ -42,22 +43,20 @@ public function testConstructorShouldRequireAnEvenNumberOfValues(): void new BoundingBox([0, 0, 1, 1, 2]); } - /** - * @dataProvider provideBoundsWithInvalidTypes - */ - public function testConstructorShouldRequireIntegerOrFloatValues(): void + #[DataProvider('provideBoundsWithInvalidTypes')] + public function testConstructorShouldRequireIntegerOrFloatValues(array $bounds): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('BoundingBox values must be integers or floats'); - new BoundingBox(func_get_args()); + new BoundingBox($bounds); } - public function provideBoundsWithInvalidTypes() + public static function provideBoundsWithInvalidTypes() { return [ - 'strings' => ['0', '0.0', '1', '1.0'], - 'objects' => [new stdClass(), new stdClass(), new stdClass(), new stdClass()], - 'arrays' => [[], [], [], []], + 'strings' => [['0', '0.0', '1', '1.0']], + 'objects' => [[new stdClass(), new stdClass(), new stdClass(), new stdClass()]], + 'arrays' => [[[], [], [], []]], ]; } @@ -78,10 +77,7 @@ public function testSerialization(): void $this->assertSame($bounds, $boundingBox->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = '[-180.0, -90.0, 180.0, 90.0]'; @@ -93,7 +89,7 @@ public function testUnserialization($assoc): void $this->assertSame([-180.0, -90.0, 180.0, 90.0], $boundingBox->getBounds()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], @@ -101,9 +97,7 @@ public function provideJsonDecodeAssocOptions() ]; } - /** - * @dataProvider provideInvalidUnserializationValues - */ + #[DataProvider('provideInvalidUnserializationValues')] public function testUnserializationShouldRequireArray($value): void { $this->expectException(UnserializationException::class); @@ -112,7 +106,7 @@ public function testUnserializationShouldRequireArray($value): void BoundingBox::jsonUnserialize($value); } - public function provideInvalidUnserializationValues() + public static function provideInvalidUnserializationValues() { return [ [null], diff --git a/tests/CoordinateReferenceSystem/LinkedTest.php b/tests/CoordinateReferenceSystem/LinkedTest.php index ef43f6a..8cb6749 100644 --- a/tests/CoordinateReferenceSystem/LinkedTest.php +++ b/tests/CoordinateReferenceSystem/LinkedTest.php @@ -7,6 +7,8 @@ use GeoJson\CoordinateReferenceSystem\CoordinateReferenceSystem; use GeoJson\CoordinateReferenceSystem\Linked; use GeoJson\Exception\UnserializationException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function is_subclass_of; @@ -50,10 +52,7 @@ public function testSerializationWithoutHrefType(): void $this->assertSame($expected, $crs->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -79,10 +78,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedProperties, $crs->getProperties()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserializationWithoutHrefType($assoc): void { $json = <<<'JSON' @@ -104,7 +100,7 @@ public function testUnserializationWithoutHrefType($assoc): void $this->assertSame($expectedProperties, $crs->getProperties()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/CoordinateReferenceSystem/NamedTest.php b/tests/CoordinateReferenceSystem/NamedTest.php index 7f98dc9..c2e6c6e 100644 --- a/tests/CoordinateReferenceSystem/NamedTest.php +++ b/tests/CoordinateReferenceSystem/NamedTest.php @@ -7,6 +7,8 @@ use GeoJson\CoordinateReferenceSystem\CoordinateReferenceSystem; use GeoJson\CoordinateReferenceSystem\Named; use GeoJson\Exception\UnserializationException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function is_subclass_of; @@ -35,10 +37,7 @@ public function testSerialization(): void $this->assertSame($expected, $crs->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -60,7 +59,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedProperties, $crs->getProperties()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Feature/FeatureCollectionTest.php b/tests/Feature/FeatureCollectionTest.php index 8d3d3d4..2509cf2 100644 --- a/tests/Feature/FeatureCollectionTest.php +++ b/tests/Feature/FeatureCollectionTest.php @@ -10,16 +10,18 @@ use GeoJson\Feature\FeatureCollection; use GeoJson\GeoJson; use GeoJson\Geometry\Point; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use stdClass; use function is_subclass_of; use function iterator_to_array; use function json_decode; -class FeatureCollectionTest extends BaseGeoJsonTest +class FeatureCollectionTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): FeatureCollection { return new FeatureCollection([], ... $extraArgs); } @@ -101,10 +103,7 @@ public function testSerialization(): void $this->assertSame($expected, $collection->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -145,7 +144,7 @@ public function testUnserialization($assoc): void $this->assertSame([1, 1], $geometry->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Feature/FeatureTest.php b/tests/Feature/FeatureTest.php index b3a5d9f..6af06f4 100644 --- a/tests/Feature/FeatureTest.php +++ b/tests/Feature/FeatureTest.php @@ -7,15 +7,17 @@ use GeoJson\Feature\Feature; use GeoJson\GeoJson; use GeoJson\Geometry\Point; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use stdClass; use function is_subclass_of; use function json_decode; -class FeatureTest extends BaseGeoJsonTest +class FeatureTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): Feature { return new Feature(null, null, null, ... $extraArgs); } @@ -76,10 +78,7 @@ public function testSerializationShouldConvertEmptyPropertiesArrayToObject(): vo $this->assertEquals($expected, $feature->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -111,7 +110,7 @@ public function testUnserialization($assoc): void $this->assertSame([1, 1], $geometry->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/GeoJsonTest.php b/tests/GeoJsonTest.php index e0ccedc..2e2d0a5 100644 --- a/tests/GeoJsonTest.php +++ b/tests/GeoJsonTest.php @@ -11,9 +11,12 @@ use GeoJson\Geometry\Point; use GeoJson\JsonUnserializable; use JsonSerializable; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function get_class; +use function get_debug_type; use function gettype; use function is_object; use function json_decode; @@ -30,10 +33,7 @@ public function testIsJsonUnserializable(): void $this->assertInstanceOf(JsonUnserializable::class, $this->createMock(GeoJson::class)); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserializationWithBoundingBox($assoc): void { $json = <<<'JSON' @@ -57,10 +57,7 @@ public function testUnserializationWithBoundingBox($assoc): void $this->assertSame([-180.0, -90.0, 180.0, 90.0], $boundingBox->getBounds()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserializationWithCrs($assoc): void { $json = <<<'JSON' @@ -116,9 +113,7 @@ public function testUnserializationWithMissingType(): void GeoJson::jsonUnserialize([]); } - /** - * @dataProvider provideGeoJsonTypesWithCoordinates - */ + #[DataProvider('provideGeoJsonTypesWithCoordinates')] public function testUnserializationWithMissingCoordinates(string $type): void { $this->expectException(UnserializationException::class); @@ -129,14 +124,11 @@ public function testUnserializationWithMissingCoordinates(string $type): void ]); } - /** - * @dataProvider provideInvalidCoordinates - * - * @param mixed $value - */ + /** @param mixed $value */ + #[DataProvider('provideInvalidCoordinates')] public function testUnserializationWithInvalidCoordinates($value): void { - $valueType = is_object($value) ? get_class($value) : gettype($value); + $valueType = get_debug_type($value); $this->expectException(UnserializationException::class); $this->expectExceptionMessage('Point expected "coordinates" property of type array, ' . $valueType . ' given'); @@ -169,7 +161,7 @@ public function testFeatureUnserializationWithInvalidProperties(): void ]); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], @@ -177,7 +169,7 @@ public function provideJsonDecodeAssocOptions() ]; } - public function provideGeoJsonTypesWithCoordinates() + public static function provideGeoJsonTypesWithCoordinates() { return [ GeoJson::TYPE_LINE_STRING => [GeoJson::TYPE_LINE_STRING], @@ -189,7 +181,7 @@ public function provideGeoJsonTypesWithCoordinates() ]; } - public function provideInvalidCoordinates() + public static function provideInvalidCoordinates() { return [ 'string' => ['1,1'], diff --git a/tests/BaseGeoJsonTest.php b/tests/GeoJsonTestCase.php similarity index 96% rename from tests/BaseGeoJsonTest.php rename to tests/GeoJsonTestCase.php index 4868aa2..efc0fa4 100644 --- a/tests/BaseGeoJsonTest.php +++ b/tests/GeoJsonTestCase.php @@ -7,17 +7,16 @@ use GeoJson\BoundingBox; use GeoJson\CoordinateReferenceSystem\CoordinateReferenceSystem; use GeoJson\Feature\Feature; +use GeoJson\GeoJson; use GeoJson\Geometry\Geometry; use PHPUnit\Framework\TestCase; -abstract class BaseGeoJsonTest extends TestCase +abstract class GeoJsonTestCase extends TestCase { /** * @param ...$extraArgs - * - * @return mixed */ - abstract public function createSubjectWithExtraArguments(...$extraArgs); + abstract public function createSubjectWithExtraArguments(...$extraArgs): GeoJson; public function testConstructorShouldScanExtraArgumentsForCrsAndBoundingBox(): void { diff --git a/tests/Geometry/GeometryCollectionTest.php b/tests/Geometry/GeometryCollectionTest.php index 50418d0..e7a19b6 100644 --- a/tests/Geometry/GeometryCollectionTest.php +++ b/tests/Geometry/GeometryCollectionTest.php @@ -10,16 +10,18 @@ use GeoJson\Geometry\Geometry; use GeoJson\Geometry\GeometryCollection; use GeoJson\Geometry\Point; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use stdClass; use function is_subclass_of; use function iterator_to_array; use function json_decode; -class GeometryCollectionTest extends BaseGeoJsonTest +class GeometryCollectionTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): GeometryCollection { return new GeometryCollection([], ... $extraArgs); } @@ -99,10 +101,7 @@ public function testSerialization(): void $this->assertSame($expected, $collection->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -132,7 +131,7 @@ public function testUnserialization($assoc): void $this->assertSame([1, 1], $geometry->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Geometry/LineStringTest.php b/tests/Geometry/LineStringTest.php index df20f46..10b0336 100644 --- a/tests/Geometry/LineStringTest.php +++ b/tests/Geometry/LineStringTest.php @@ -8,14 +8,16 @@ use GeoJson\GeoJson; use GeoJson\Geometry\LineString; use GeoJson\Geometry\MultiPoint; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function is_subclass_of; use function json_decode; -class LineStringTest extends BaseGeoJsonTest +class LineStringTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): LineString { return new LineString( [[1, 1], [2, 2]], @@ -51,10 +53,7 @@ public function testSerialization(): void $this->assertSame($expected, $lineString->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -77,7 +76,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedCoordinates, $lineString->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Geometry/LinearRingTest.php b/tests/Geometry/LinearRingTest.php index 367f4b9..a91ae31 100644 --- a/tests/Geometry/LinearRingTest.php +++ b/tests/Geometry/LinearRingTest.php @@ -9,13 +9,14 @@ use GeoJson\Geometry\LinearRing; use GeoJson\Geometry\LineString; use GeoJson\Geometry\Point; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use function is_subclass_of; -class LinearRingTest extends BaseGeoJsonTest +class LinearRingTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): LinearRing { return new LinearRing( [[1, 1], [2, 2], [3, 3], [1, 1]], @@ -53,9 +54,7 @@ public function testConstructorShouldRequireEquivalentFirstAndLastPositions(): v ]); } - /** - * @doesNotPerformAssertions - */ + #[DoesNotPerformAssertions] public function testConstructorShouldAcceptEquivalentPointObjectsAndPositionArrays(): void { new LinearRing([ diff --git a/tests/Geometry/MultiLineStringTest.php b/tests/Geometry/MultiLineStringTest.php index d4f1a1b..0b5aae6 100644 --- a/tests/Geometry/MultiLineStringTest.php +++ b/tests/Geometry/MultiLineStringTest.php @@ -8,14 +8,16 @@ use GeoJson\Geometry\Geometry; use GeoJson\Geometry\LineString; use GeoJson\Geometry\MultiLineString; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function is_subclass_of; use function json_decode; -class MultiLineStringTest extends BaseGeoJsonTest +class MultiLineStringTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): MultiLineString { return new MultiLineString([], ... $extraArgs); } @@ -59,10 +61,7 @@ public function testSerialization(): void $this->assertSame($expected, $multiLineString->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -88,7 +87,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedCoordinates, $multiLineString->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Geometry/MultiPointTest.php b/tests/Geometry/MultiPointTest.php index 30a5266..9f3153d 100644 --- a/tests/Geometry/MultiPointTest.php +++ b/tests/Geometry/MultiPointTest.php @@ -8,14 +8,16 @@ use GeoJson\Geometry\Geometry; use GeoJson\Geometry\MultiPoint; use GeoJson\Geometry\Point; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function is_subclass_of; use function json_decode; -class MultiPointTest extends BaseGeoJsonTest +class MultiPointTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): MultiPoint { return new MultiPoint([], ... $extraArgs); } @@ -55,10 +57,7 @@ public function testSerialization(): void $this->assertSame($expected, $multiPoint->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -81,7 +80,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedCoordinates, $multiPoint->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Geometry/MultiPolygonTest.php b/tests/Geometry/MultiPolygonTest.php index 58ad275..811bb96 100644 --- a/tests/Geometry/MultiPolygonTest.php +++ b/tests/Geometry/MultiPolygonTest.php @@ -8,14 +8,16 @@ use GeoJson\Geometry\Geometry; use GeoJson\Geometry\MultiPolygon; use GeoJson\Geometry\Polygon; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function is_subclass_of; use function json_decode; -class MultiPolygonTest extends BaseGeoJsonTest +class MultiPolygonTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): MultiPolygon { return new MultiPolygon([], ... $extraArgs); } @@ -59,10 +61,7 @@ public function testSerialization(): void $this->assertSame($expected, $multiPolygon->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -88,7 +87,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedCoordinates, $multiPolygon->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Geometry/PointTest.php b/tests/Geometry/PointTest.php index a3acbe6..a3ddf75 100644 --- a/tests/Geometry/PointTest.php +++ b/tests/Geometry/PointTest.php @@ -8,16 +8,17 @@ use GeoJson\GeoJson; use GeoJson\Geometry\Geometry; use GeoJson\Geometry\Point; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use stdClass; -use function func_get_args; use function is_subclass_of; use function json_decode; -class PointTest extends BaseGeoJsonTest +class PointTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): Point { return new Point([1, 1], ... $extraArgs); } @@ -35,23 +36,21 @@ public function testConstructorShouldRequireAtLeastTwoElementsInPosition(): void new Point([1]); } - /** - * @dataProvider providePositionsWithInvalidTypes - */ - public function testConstructorShouldRequireIntegerOrFloatElementsInPosition(): void + #[DataProvider('providePositionsWithInvalidTypes')] + public function testConstructorShouldRequireIntegerOrFloatElementsInPosition(array $position): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Position elements must be integers or floats'); - new Point(func_get_args()); + new Point($position); } - public function providePositionsWithInvalidTypes() + public static function providePositionsWithInvalidTypes() { return [ - 'strings' => ['1.0', '2'], - 'objects' => [new stdClass(), new stdClass()], - 'arrays' => [[], []], + 'strings' => [['1.0', '2']], + 'objects' => [[new stdClass(), new stdClass()]], + 'arrays' => [[[], []]], ]; } @@ -77,10 +76,7 @@ public function testSerialization(): void $this->assertSame($expected, $point->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -98,7 +94,7 @@ public function testUnserialization($assoc): void $this->assertSame([1, 1], $point->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true], diff --git a/tests/Geometry/PolygonTest.php b/tests/Geometry/PolygonTest.php index c71d393..f4953a3 100644 --- a/tests/Geometry/PolygonTest.php +++ b/tests/Geometry/PolygonTest.php @@ -8,14 +8,16 @@ use GeoJson\Geometry\Geometry; use GeoJson\Geometry\LinearRing; use GeoJson\Geometry\Polygon; -use GeoJson\Tests\BaseGeoJsonTest; +use GeoJson\Tests\GeoJsonTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function is_subclass_of; use function json_decode; -class PolygonTest extends BaseGeoJsonTest +class PolygonTest extends GeoJsonTestCase { - public function createSubjectWithExtraArguments(...$extraArgs) + public function createSubjectWithExtraArguments(...$extraArgs): Polygon { return new Polygon( [ @@ -65,10 +67,7 @@ public function testSerialization(): void $this->assertSame($expected, $polygon->jsonSerialize()); } - /** - * @dataProvider provideJsonDecodeAssocOptions - * @group functional - */ + #[DataProvider('provideJsonDecodeAssocOptions')] public function testUnserialization($assoc): void { $json = <<<'JSON' @@ -94,7 +93,7 @@ public function testUnserialization($assoc): void $this->assertSame($expectedCoordinates, $polygon->getCoordinates()); } - public function provideJsonDecodeAssocOptions() + public static function provideJsonDecodeAssocOptions() { return [ 'assoc=true' => [true],