Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
{ "name": "Jeremy Mikola", "email": "[email protected]" }
],
"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"
Expand Down
8 changes: 3 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
Expand All @@ -10,10 +9,9 @@
<directory>./tests/</directory>
</testsuite>
</testsuites>

<coverage ignoreDeprecatedCodeUnits="true" processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">./src/</directory>
<directory>./src/</directory>
</include>
</coverage>
</source>
</phpunit>
15 changes: 5 additions & 10 deletions src/CoordinateReferenceSystem/CoordinateReferenceSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,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),
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnserializationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/GeoJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
26 changes: 11 additions & 15 deletions tests/BoundingBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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;

Expand Down Expand Up @@ -42,17 +44,15 @@ public function testConstructorShouldRequireAnEvenNumberOfValues(): void
new BoundingBox([0, 0, 1, 1, 2]);
}

/**
* @dataProvider provideBoundsWithInvalidTypes
*/
public function testConstructorShouldRequireIntegerOrFloatValues(): void
#[DataProvider('provideBoundsWithInvalidTypes')]
public function testConstructorShouldRequireIntegerOrFloatValues(mixed ...$args): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('BoundingBox values must be integers or floats');
new BoundingBox(func_get_args());
new BoundingBox($args);
}

public function provideBoundsWithInvalidTypes()
public static function provideBoundsWithInvalidTypes()
{
return [
'strings' => ['0', '0.0', '1', '1.0'],
Expand All @@ -78,10 +78,8 @@ public function testSerialization(): void
$this->assertSame($bounds, $boundingBox->jsonSerialize());
}

/**
* @dataProvider provideJsonDecodeAssocOptions
* @group functional
*/
#[DataProvider('provideJsonDecodeAssocOptions')]
#[Group('functional')]
public function testUnserialization($assoc): void
{
$json = '[-180.0, -90.0, 180.0, 90.0]';
Expand All @@ -93,17 +91,15 @@ 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],
'assoc=false' => [false],
];
}

/**
* @dataProvider provideInvalidUnserializationValues
*/
#[DataProvider('provideInvalidUnserializationValues')]
public function testUnserializationShouldRequireArray($value): void
{
$this->expectException(UnserializationException::class);
Expand All @@ -112,7 +108,7 @@ public function testUnserializationShouldRequireArray($value): void
BoundingBox::jsonUnserialize($value);
}

public function provideInvalidUnserializationValues()
public static function provideInvalidUnserializationValues()
{
return [
[null],
Expand Down
16 changes: 7 additions & 9 deletions tests/CoordinateReferenceSystem/LinkedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,10 +52,8 @@ public function testSerializationWithoutHrefType(): void
$this->assertSame($expected, $crs->jsonSerialize());
}

/**
* @dataProvider provideJsonDecodeAssocOptions
* @group functional
*/
#[DataProvider('provideJsonDecodeAssocOptions')]
#[Group('functional')]
public function testUnserialization($assoc): void
{
$json = <<<'JSON'
Expand All @@ -79,10 +79,8 @@ public function testUnserialization($assoc): void
$this->assertSame($expectedProperties, $crs->getProperties());
}

/**
* @dataProvider provideJsonDecodeAssocOptions
* @group functional
*/
#[DataProvider('provideJsonDecodeAssocOptions')]
#[Group('functional')]
public function testUnserializationWithoutHrefType($assoc): void
{
$json = <<<'JSON'
Expand All @@ -104,7 +102,7 @@ public function testUnserializationWithoutHrefType($assoc): void
$this->assertSame($expectedProperties, $crs->getProperties());
}

public function provideJsonDecodeAssocOptions()
public static function provideJsonDecodeAssocOptions()
{
return [
'assoc=true' => [true],
Expand Down
10 changes: 5 additions & 5 deletions tests/CoordinateReferenceSystem/NamedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,10 +37,8 @@ public function testSerialization(): void
$this->assertSame($expected, $crs->jsonSerialize());
}

/**
* @dataProvider provideJsonDecodeAssocOptions
* @group functional
*/
#[DataProvider('provideJsonDecodeAssocOptions')]
#[Group('functional')]
public function testUnserialization($assoc): void
{
$json = <<<'JSON'
Expand All @@ -60,7 +60,7 @@ public function testUnserialization($assoc): void
$this->assertSame($expectedProperties, $crs->getProperties());
}

public function provideJsonDecodeAssocOptions()
public static function provideJsonDecodeAssocOptions()
{
return [
'assoc=true' => [true],
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/FeatureCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
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)
{
Expand Down Expand Up @@ -101,10 +103,8 @@ public function testSerialization(): void
$this->assertSame($expected, $collection->jsonSerialize());
}

/**
* @dataProvider provideJsonDecodeAssocOptions
* @group functional
*/
#[DataProvider('provideJsonDecodeAssocOptions')]
#[Group('functional')]
public function testUnserialization($assoc): void
{
$json = <<<'JSON'
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testUnserialization($assoc): void
$this->assertSame([1, 1], $geometry->getCoordinates());
}

public function provideJsonDecodeAssocOptions()
public static function provideJsonDecodeAssocOptions()
{
return [
'assoc=true' => [true],
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
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)
{
Expand Down Expand Up @@ -76,10 +78,8 @@ public function testSerializationShouldConvertEmptyPropertiesArrayToObject(): vo
$this->assertEquals($expected, $feature->jsonSerialize());
}

/**
* @dataProvider provideJsonDecodeAssocOptions
* @group functional
*/
#[DataProvider('provideJsonDecodeAssocOptions')]
#[Group('functional')]
public function testUnserialization($assoc): void
{
$json = <<<'JSON'
Expand Down Expand Up @@ -111,7 +111,7 @@ public function testUnserialization($assoc): void
$this->assertSame([1, 1], $geometry->getCoordinates());
}

public function provideJsonDecodeAssocOptions()
public static function provideJsonDecodeAssocOptions()
{
return [
'assoc=true' => [true],
Expand Down
Loading