diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c1b4c03..c91be19 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: [ '8.1', '8.2', '8.3' ]
+ php: [ '7.3', '7.4', '8.0' ]
steps:
- id: checkout
@@ -23,7 +23,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- tools: composer:v2, php-cs-fixer
+ tools: composer:v2
- name: Validate composer.json and composer.lock
run: composer validate
@@ -60,7 +60,7 @@ jobs:
name: CGL
if: ${{ always() && steps.install.conclusion == 'success' }}
run: |
- php-cs-fixer fix --dry-run --verbose
+ composer ci:cgl -- --dry-run
- id: phpstan
name: PHPStan
diff --git a/.gitignore b/.gitignore
index c6fd842..13f6a02 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ composer.lock
# Cache
.php-cs-fixer.cache
+.php_cs.cache
.phplint.cache
.phpunit.result.cache
.phpunit.cache
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 4a50534..0042ae2 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -40,7 +40,6 @@
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
- '@PER-CS2.0' => true,
'@Symfony' => true,
// Additional custom rules
@@ -57,19 +56,9 @@
'phpdoc_to_comment' => false,
'phpdoc_no_alias_tag' => false,
'no_superfluous_phpdoc_tags' => false,
- 'phpdoc_separation' => [
- 'groups' => [
- [
- 'author',
- 'license',
- 'link',
- ],
- ],
- ],
+ 'phpdoc_separation' => true,
'no_alias_functions' => true,
- 'whitespace_after_comma_in_array' => [
- 'ensure_single_space' => true,
- ],
+ 'whitespace_after_comma_in_array' => true,
'single_line_throw' => false,
'self_accessor' => false,
'global_namespace_import' => [
@@ -79,7 +68,6 @@
],
'function_declaration' => [
'closure_function_spacing' => 'one',
- 'closure_fn_spacing' => 'one',
],
'binary_operator_spaces' => [
'operators' => [
diff --git a/composer.json b/composer.json
index c80646e..b01cb04 100644
--- a/composer.json
+++ b/composer.json
@@ -14,18 +14,18 @@
"issues": "https://github.com/magicsunday/jsonmapper/issues"
},
"require": {
- "php": ">=8.1.0 <8.4.0",
+ "php": ">=7.3.0 <8.1.0",
"ext-json": "*",
- "symfony/property-info": "^6.0 || ^7.0",
- "symfony/property-access": "^6.0 || ^7.0",
- "doctrine/inflector": "^2.0",
- "doctrine/annotations": "^2.0"
+ "symfony/property-info": "^5.0 || ^6.0 || ^7.0",
+ "symfony/property-access": "^5.0 || ^6.0 || ^7.0",
+ "doctrine/inflector": "^1.0 || ^2.0",
+ "doctrine/annotations": "^1.0 || ^2.0"
},
"require-dev": {
- "phpdocumentor/reflection-docblock": "^5.0",
- "friendsofphp/php-cs-fixer": "^3.50",
- "overtrue/phplint": "^3.4 || ^9.0",
- "phpunit/phpunit": "^10.0 || ^11.0",
+ "phpdocumentor/reflection-docblock": "^4.0 || ^5.0",
+ "friendsofphp/php-cs-fixer": "^2.0",
+ "overtrue/phplint": "^2.0 || ^3.0 || ^9.0",
+ "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
diff --git a/phpunit.xml b/phpunit.xml
index 4b92d24..5e23aa0 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,20 +1,19 @@
./test
-
+
diff --git a/rector.php b/rector.php
index 6ce49fb..07882f5 100644
--- a/rector.php
+++ b/rector.php
@@ -15,9 +15,6 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
-use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
-use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
-use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
@@ -44,17 +41,14 @@
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
- LevelSetList::UP_TO_PHP_81,
+ LevelSetList::UP_TO_PHP_73,
]);
// Skip some rules
$rectorConfig->skip([
CatchExceptionNameMatchingTypeRector::class,
- ClassPropertyAssignToConstructorPromotionRector::class,
LocallyCalledStaticMethodToNonStaticRector::class,
- MixedTypeRector::class,
ParamTypeByMethodCallTypeRector::class,
- ReadOnlyPropertyRector::class,
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
RemoveUselessVarTagRector::class,
diff --git a/src/JsonMapper.php b/src/JsonMapper.php
index 83a8ce5..c83dde0 100644
--- a/src/JsonMapper.php
+++ b/src/JsonMapper.php
@@ -11,11 +11,14 @@
namespace MagicSunday;
+use function array_key_exists;
use Closure;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\AnnotationReader;
use DomainException;
+use function in_array;
use InvalidArgumentException;
+use function is_array;
use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue;
use MagicSunday\JsonMapper\Annotation\ReplaceProperty;
use MagicSunday\JsonMapper\Converter\PropertyNameConverterInterface;
@@ -27,15 +30,12 @@
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\PropertyInfo\Type;
-use function array_key_exists;
-use function in_array;
-use function is_array;
-
/**
* JsonMapper.
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*
* @template TEntity
@@ -46,19 +46,19 @@ class JsonMapper
/**
* @var PropertyInfoExtractorInterface
*/
- private PropertyInfoExtractorInterface $extractor;
+ private $extractor;
/**
* @var PropertyAccessorInterface
*/
- private PropertyAccessorInterface $accessor;
+ private $accessor;
/**
* The property name converter instance.
*
* @var PropertyNameConverterInterface|null
*/
- protected ?PropertyNameConverterInterface $nameConverter;
+ protected $nameConverter;
/**
* Override class names that JsonMapper uses to create objects. Useful when your
@@ -66,21 +66,21 @@ class JsonMapper
*
* @var string[]|Closure[]
*/
- private array $classMap;
+ private $classMap;
/**
* The default value type instance.
*
* @var Type
*/
- private Type $defaultType;
+ private $defaultType;
/**
* The custom types.
*
* @var Closure[]
*/
- private array $types = [];
+ private $types = [];
/**
* JsonMapper constructor.
@@ -302,7 +302,7 @@ private function getReflectionProperty(string $className, string $propertyName):
{
try {
return new ReflectionProperty($className, $propertyName);
- } catch (ReflectionException) {
+ } catch (ReflectionException $exception) {
return null;
}
}
@@ -421,7 +421,7 @@ private function getDefaultValue(string $className, string $propertyName)
return null;
}
- return $reflectionProperty->getDefaultValue();
+ return $reflectionProperty->getDeclaringClass()->getDefaultProperties()[$propertyName] ?? null;
}
/**
diff --git a/src/JsonMapper/Converter/CamelCasePropertyNameConverter.php b/src/JsonMapper/Converter/CamelCasePropertyNameConverter.php
index e57aba3..9e4dc06 100644
--- a/src/JsonMapper/Converter/CamelCasePropertyNameConverter.php
+++ b/src/JsonMapper/Converter/CamelCasePropertyNameConverter.php
@@ -19,6 +19,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class CamelCasePropertyNameConverter implements PropertyNameConverterInterface
@@ -26,7 +27,7 @@ class CamelCasePropertyNameConverter implements PropertyNameConverterInterface
/**
* @var Inflector
*/
- private Inflector $inflector;
+ private $inflector;
/**
* CamelCasePropertyNameConverter constructor.
diff --git a/src/JsonMapper/Converter/PropertyNameConverterInterface.php b/src/JsonMapper/Converter/PropertyNameConverterInterface.php
index 80c3c28..1819abb 100644
--- a/src/JsonMapper/Converter/PropertyNameConverterInterface.php
+++ b/src/JsonMapper/Converter/PropertyNameConverterInterface.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
interface PropertyNameConverterInterface
diff --git a/test/Annotation/ReplacePropertyTest.php b/test/Annotation/ReplacePropertyTest.php
index ec97bcf..21a920b 100644
--- a/test/Annotation/ReplacePropertyTest.php
+++ b/test/Annotation/ReplacePropertyTest.php
@@ -20,14 +20,16 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class ReplacePropertyTest extends TestCase
{
/**
* Tests replacing a property.
+ *
+ * @test
*/
- #[Test]
public function replaceProperty(): void
{
$result = $this->getJsonMapper()
diff --git a/test/Classes/Base.php b/test/Classes/Base.php
index bc04379..8497115 100644
--- a/test/Classes/Base.php
+++ b/test/Classes/Base.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class Base
@@ -61,7 +62,7 @@ class Base
/**
* @var string
*/
- private string $privateProperty = '';
+ private $privateProperty = '';
/**
* @return string
diff --git a/test/Classes/ClassMap/CollectionSource.php b/test/Classes/ClassMap/CollectionSource.php
index ff07cf5..8a47864 100644
--- a/test/Classes/ClassMap/CollectionSource.php
+++ b/test/Classes/ClassMap/CollectionSource.php
@@ -18,6 +18,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class CollectionSource extends Collection
diff --git a/test/Classes/ClassMap/CollectionTarget.php b/test/Classes/ClassMap/CollectionTarget.php
index a649180..4650897 100644
--- a/test/Classes/ClassMap/CollectionTarget.php
+++ b/test/Classes/ClassMap/CollectionTarget.php
@@ -18,6 +18,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class CollectionTarget extends ArrayObject
diff --git a/test/Classes/ClassMap/SourceItem.php b/test/Classes/ClassMap/SourceItem.php
index 0fcfdc2..9cb9d2c 100644
--- a/test/Classes/ClassMap/SourceItem.php
+++ b/test/Classes/ClassMap/SourceItem.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class SourceItem
diff --git a/test/Classes/ClassMap/TargetItem.php b/test/Classes/ClassMap/TargetItem.php
index f29954f..98206d2 100644
--- a/test/Classes/ClassMap/TargetItem.php
+++ b/test/Classes/ClassMap/TargetItem.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class TargetItem
diff --git a/test/Classes/Collection.php b/test/Classes/Collection.php
index 0881d65..e684169 100644
--- a/test/Classes/Collection.php
+++ b/test/Classes/Collection.php
@@ -19,6 +19,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*
* @template TKey of array-key
diff --git a/test/Classes/CustomClass.php b/test/Classes/CustomClass.php
index f3acf2b..fe01aec 100644
--- a/test/Classes/CustomClass.php
+++ b/test/Classes/CustomClass.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class CustomClass
@@ -25,5 +26,5 @@ class CustomClass
*
* or alternatively use Collection
*/
- public array $persons = [];
+ public $persons = [];
}
diff --git a/test/Classes/CustomConstructor.php b/test/Classes/CustomConstructor.php
index f1b1455..544dae4 100644
--- a/test/Classes/CustomConstructor.php
+++ b/test/Classes/CustomConstructor.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class CustomConstructor
diff --git a/test/Classes/Initialized.php b/test/Classes/Initialized.php
index fa29a41..188a1cd 100644
--- a/test/Classes/Initialized.php
+++ b/test/Classes/Initialized.php
@@ -11,11 +11,14 @@
namespace MagicSunday\Test\Classes;
+use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue;
+
/**
* Class Initialized.
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class Initialized
@@ -23,21 +26,21 @@ class Initialized
/**
* @var int
*
- * @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
+ * @ReplaceNullWithDefaultValue
*/
- public int $integer = 10;
+ public $integer = 10;
/**
* @var bool
*
- * @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
+ * @ReplaceNullWithDefaultValue
*/
- public bool $bool = false;
+ public $bool = false;
/**
* @var array
*
- * @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
+ * @ReplaceNullWithDefaultValue
*/
- public array $array = [];
+ public $array = [];
}
diff --git a/test/Classes/MapPlainArrayKeyValueClass.php b/test/Classes/MapPlainArrayKeyValueClass.php
index 707f423..a3547b4 100644
--- a/test/Classes/MapPlainArrayKeyValueClass.php
+++ b/test/Classes/MapPlainArrayKeyValueClass.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class MapPlainArrayKeyValueClass
diff --git a/test/Classes/MultidimensionalArray.php b/test/Classes/MultidimensionalArray.php
index 0f0a793..349c36c 100644
--- a/test/Classes/MultidimensionalArray.php
+++ b/test/Classes/MultidimensionalArray.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class MultidimensionalArray
@@ -25,5 +26,5 @@ class MultidimensionalArray
*
* or alternatively use @var array>
*/
- public array $persons;
+ public $persons;
}
diff --git a/test/Classes/Person.php b/test/Classes/Person.php
index 01985bf..dd3abd3 100644
--- a/test/Classes/Person.php
+++ b/test/Classes/Person.php
@@ -18,6 +18,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*
* @property int $oscars Dynamic created property
@@ -28,10 +29,10 @@ class Person
/**
* @var bool
*/
- public bool $is_vip = false;
+ public $is_vip = false;
/**
* @var string
*/
- public string $name;
+ public $name;
}
diff --git a/test/Classes/PlainArrayClass.php b/test/Classes/PlainArrayClass.php
index c019362..daff602 100644
--- a/test/Classes/PlainArrayClass.php
+++ b/test/Classes/PlainArrayClass.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class PlainArrayClass
@@ -23,7 +24,7 @@ class PlainArrayClass
/**
* @var array
*/
- public array $values;
+ public $values;
/**
* @return array
diff --git a/test/Classes/ReplacePropertyTestClass.php b/test/Classes/ReplacePropertyTestClass.php
index 90aa633..0ec0e5a 100644
--- a/test/Classes/ReplacePropertyTestClass.php
+++ b/test/Classes/ReplacePropertyTestClass.php
@@ -18,6 +18,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*
* @ReplaceProperty("type", replaces="ftype")
diff --git a/test/Classes/Simple.php b/test/Classes/Simple.php
index 944e88f..1c312e4 100644
--- a/test/Classes/Simple.php
+++ b/test/Classes/Simple.php
@@ -16,21 +16,24 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class Simple
{
/**
* PHP7.4 typed property.
+ *
+ * @var int
*/
- public int $id;
+ public $id;
/**
* PHP7.4 typed property.
*
* @var string
*/
- public string $name;
+ public $name;
/**
* @var int
diff --git a/test/Classes/VariadicSetterClass.php b/test/Classes/VariadicSetterClass.php
index c7c5dea..70744a5 100644
--- a/test/Classes/VariadicSetterClass.php
+++ b/test/Classes/VariadicSetterClass.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class VariadicSetterClass
@@ -23,7 +24,7 @@ class VariadicSetterClass
/**
* @var int[]
*/
- private array $values;
+ private $values;
/**
* @return int[]
diff --git a/test/Classes/VipPerson.php b/test/Classes/VipPerson.php
index 9bcae8e..0a25db1 100644
--- a/test/Classes/VipPerson.php
+++ b/test/Classes/VipPerson.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class VipPerson extends Person
@@ -23,17 +24,17 @@ class VipPerson extends Person
/**
* @var bool
*/
- public bool $is_vip = true;
+ public $is_vip = true;
/**
* Number of oscars won.
*
* @var int
*/
- public int $oscars;
+ public $oscars;
/**
* @var string
*/
- public string $name;
+ public $name;
}
diff --git a/test/Converter/CamelCasePropertyNameConverterTest.php b/test/Converter/CamelCasePropertyNameConverterTest.php
index 2805fb6..087e1ba 100644
--- a/test/Converter/CamelCasePropertyNameConverterTest.php
+++ b/test/Converter/CamelCasePropertyNameConverterTest.php
@@ -20,14 +20,16 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class CamelCasePropertyNameConverterTest extends TestCase
{
/**
* Tests mapping json properties to camel case.
+ *
+ * @test
*/
- #[Test]
public function checkCamelCasePropertyNameConverter(): void
{
$converter = new CamelCasePropertyNameConverter();
diff --git a/test/JsonMapperTest.php b/test/JsonMapperTest.php
index df54f2e..74485f6 100644
--- a/test/JsonMapperTest.php
+++ b/test/JsonMapperTest.php
@@ -27,8 +27,7 @@
use MagicSunday\Test\Classes\Simple;
use MagicSunday\Test\Classes\VariadicSetterClass;
use MagicSunday\Test\Classes\VipPerson;
-use PHPUnit\Framework\Attributes\DataProvider;
-use PHPUnit\Framework\Attributes\Test;
+use MagicSunday\Test\Provider\DataProvider;
use stdClass;
/**
@@ -36,6 +35,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class JsonMapperTest extends TestCase
@@ -47,10 +47,10 @@ public static function mapArrayOrCollectionWithIntegerKeysJsonDataProvider(): ar
{
return [
'mapArray' => [
- Provider\DataProvider::mapArrayJson(),
+ DataProvider::mapArrayJson(),
],
'mapCollection' => [
- Provider\DataProvider::mapCollectionJson(),
+ DataProvider::mapCollectionJson(),
],
];
}
@@ -58,10 +58,12 @@ public static function mapArrayOrCollectionWithIntegerKeysJsonDataProvider(): ar
/**
* Tests mapping an array or collection of objects.
*
+ * @dataProvider mapArrayOrCollectionWithIntegerKeysJsonDataProvider
+ *
+ * @test
+ *
* @param string $jsonString
*/
- #[Test]
- #[DataProvider('mapArrayOrCollectionWithIntegerKeysJsonDataProvider')]
public function mapArrayOrCollection(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -79,8 +81,9 @@ public function mapArrayOrCollection(string $jsonString): void
/**
* Tests mapping an array or collection of objects.
+ *
+ * @test
*/
- #[Test]
public function mapArrayOrCollectionWithStringKeys(): void
{
$result = $this->getJsonMapper()
@@ -123,7 +126,7 @@ public static function mapSimpleArrayJsonDataProvider(): array
{
return [
'mapSimpleArray' => [
- Provider\DataProvider::mapSimpleArrayJson(),
+ DataProvider::mapSimpleArrayJson(),
],
];
}
@@ -131,10 +134,12 @@ public static function mapSimpleArrayJsonDataProvider(): array
/**
* Tests mapping an array of objects to a property.
*
+ * @dataProvider mapSimpleArrayJsonDataProvider
+ *
+ * @test
+ *
* @param string $jsonString
*/
- #[Test]
- #[DataProvider('mapSimpleArrayJsonDataProvider')]
public function mapSimpleArray(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -160,7 +165,7 @@ public static function mapSimpleCollectionJsonDataProvider(): array
{
return [
'mapSimpleCollection' => [
- Provider\DataProvider::mapSimpleCollectionJson(),
+ DataProvider::mapSimpleCollectionJson(),
],
];
}
@@ -168,10 +173,12 @@ public static function mapSimpleCollectionJsonDataProvider(): array
/**
* Tests mapping a collection of objects to a property.
*
+ * @dataProvider mapSimpleCollectionJsonDataProvider
+ *
+ * @test
+ *
* @param string $jsonString
*/
- #[Test]
- #[DataProvider('mapSimpleCollectionJsonDataProvider')]
public function mapSimpleCollection(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -197,7 +204,7 @@ public static function mapCustomTypeJsonDataProvider(): array
{
return [
'mapCustomType' => [
- Provider\DataProvider::mapCustomTypeJson(),
+ DataProvider::mapCustomTypeJson(),
],
];
}
@@ -205,10 +212,12 @@ public static function mapCustomTypeJsonDataProvider(): array
/**
* Tests mapping a value using a custom type mapper closure.
*
+ * @dataProvider mapCustomTypeJsonDataProvider
+ *
+ * @test
+ *
* @param string $jsonString
*/
- #[Test]
- #[DataProvider('mapCustomTypeJsonDataProvider')]
public function mapCustomType(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -243,7 +252,7 @@ public static function mapSimpleTypesJsonDataProvider(): array
{
return [
'mapCustomType' => [
- Provider\DataProvider::mapSimpleTypesJson(),
+ DataProvider::mapSimpleTypesJson(),
],
];
}
@@ -251,10 +260,12 @@ public static function mapSimpleTypesJsonDataProvider(): array
/**
* Tests mapping simple types.
*
+ * @dataProvider mapSimpleTypesJsonDataProvider
+ *
+ * @test
+ *
* @param string $jsonString
*/
- #[Test]
- #[DataProvider('mapSimpleTypesJsonDataProvider')]
public function mapSimpleTypesJson(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -286,7 +297,7 @@ public static function mapObjectUsingCustomClassNameJsonDataProvider(): array
{
return [
'mapCustomClassName' => [
- Provider\DataProvider::mapCustomClassNameJson(),
+ DataProvider::mapCustomClassNameJson(),
],
];
}
@@ -294,10 +305,12 @@ public static function mapObjectUsingCustomClassNameJsonDataProvider(): array
/**
* Tests mapping an object using a custom class name provider closure.
*
+ * @dataProvider mapObjectUsingCustomClassNameJsonDataProvider
+ *
+ * @test
+ *
* @param string $jsonString
*/
- #[Test]
- #[DataProvider('mapObjectUsingCustomClassNameJsonDataProvider')]
public function mapObjectUsingCustomClassName(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -334,8 +347,9 @@ static function ($value): string {
/**
* Tests mapping null to an object not failing.
+ *
+ * @test
*/
- #[Test]
public function mapEmptyObject(): void
{
$result = $this->getJsonMapper()
@@ -355,8 +369,9 @@ public function mapEmptyObject(): void
/**
* Tests mapping a value to a private property using a setter method.
+ *
+ * @test
*/
- #[Test]
public function mapToPrivateProperty(): void
{
$result = $this->getJsonMapper()
@@ -376,8 +391,9 @@ public function mapToPrivateProperty(): void
/**
* Tests mapping json properties to camel case.
+ *
+ * @test
*/
- #[Test]
public function checkCamelCasePropertyConverter(): void
{
$result = $this->getJsonMapper()
@@ -397,8 +413,9 @@ public function checkCamelCasePropertyConverter(): void
/**
* Tests mapping a JSON array with objects into a plain PHP array with objects of given class.
+ *
+ * @test
*/
- #[Test]
public function mapArrayOfObjects(): void
{
$result = $this->getJsonMapper()
@@ -426,8 +443,9 @@ public function mapArrayOfObjects(): void
/**
* Tests mapping a JSON object into an PHP object ignoring a given collection class as the
* JSON does not contain a collection.
+ *
+ * @test
*/
- #[Test]
public function mapSingleObjectWithGivenCollection(): void
{
$result = $this->getJsonMapper()
@@ -448,8 +466,9 @@ public function mapSingleObjectWithGivenCollection(): void
/**
* Tests mapping of a multidimensional array.
+ *
+ * @test
*/
- #[Test]
public function mapArrayOfArray(): void
{
$result = $this->getJsonMapper()
@@ -489,8 +508,9 @@ public function mapArrayOfArray(): void
/**
* Tests mapping of values with an initial value.
+ *
+ * @test
*/
- #[Test]
public function mapInitialized(): void
{
$result = $this->getJsonMapper()
@@ -508,8 +528,9 @@ public function mapInitialized(): void
/**
* Tests mapping of default values using @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
* annotation in case JSON contains NULL.
+ *
+ * @test
*/
- #[Test]
public function mapNullToDefaultValueUsingAnnotation(): void
{
$result = $this->getJsonMapper()
@@ -537,16 +558,18 @@ public static function mapPlainArrayJsonDataProvider(): array
{
return [
'mapPlainArray' => [
- Provider\DataProvider::mapPlainArrayJson(),
+ DataProvider::mapPlainArrayJson(),
],
];
}
/**
+ * @dataProvider mapPlainArrayJsonDataProvider
+ *
* @param string $jsonString
+ *
+ * @test
*/
- #[Test]
- #[DataProvider('mapPlainArrayJsonDataProvider')]
public function mapPlainArray(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -573,16 +596,18 @@ public static function mapPlainArrayKeyValueJsonDataProvider(): array
{
return [
'mapPlainArrayKeyValue' => [
- Provider\DataProvider::mapPlainArrayKeyValueJson(),
+ DataProvider::mapPlainArrayKeyValueJson(),
],
];
}
/**
+ * @dataProvider mapPlainArrayKeyValueJsonDataProvider
+ *
* @param string $jsonString
+ *
+ * @test
*/
- #[Test]
- #[DataProvider('mapPlainArrayKeyValueJsonDataProvider')]
public function mapPlainArrayKeyValue(string $jsonString): void
{
$result = $this->getJsonMapper()
@@ -626,8 +651,9 @@ public function mapPlainArrayKeyValue(string $jsonString): void
/**
* Tests settings a class property using a variadic setter method.
+ *
+ * @test
*/
- #[Test]
public function variadicSetter(): void
{
$result = $this->getJsonMapper()
@@ -653,8 +679,9 @@ public function variadicSetter(): void
/**
* Tests settings a plain array.
+ *
+ * @test
*/
- #[Test]
public function plainArrayClass(): void
{
$result = $this->getJsonMapper()
@@ -680,8 +707,9 @@ public function plainArrayClass(): void
/**
* Tests mapping an object to a custom class using a class map entry.
+ *
+ * @test
*/
- #[Test]
public function mappingBaseElementUsingClassMap(): void
{
$result = $this->getJsonMapper([
@@ -703,8 +731,9 @@ public function mappingBaseElementUsingClassMap(): void
/**
* Tests mapping a collection of objects to a custom class using a class map entry.
+ *
+ * @test
*/
- #[Test]
public function mappingCollectionElementsUsingClassMap(): void
{
$result = $this->getJsonMapper([
diff --git a/test/Provider/DataProvider.php b/test/Provider/DataProvider.php
index bc287c4..7617306 100644
--- a/test/Provider/DataProvider.php
+++ b/test/Provider/DataProvider.php
@@ -16,6 +16,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class DataProvider
diff --git a/test/TestCase.php b/test/TestCase.php
index 8ae253b..8492b7e 100644
--- a/test/TestCase.php
+++ b/test/TestCase.php
@@ -25,6 +25,7 @@
*
* @author Rico Sonntag
* @license https://opensource.org/licenses/MIT
+ *
* @link https://github.com/magicsunday/jsonmapper/
*/
class TestCase extends \PHPUnit\Framework\TestCase
@@ -57,7 +58,7 @@ protected function getJsonMapper(array $classMap = []): JsonMapper
*
* @return mixed|null
*/
- protected function getJsonAsArray(string $jsonString): mixed
+ protected function getJsonAsArray(string $jsonString)
{
try {
return json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
@@ -73,7 +74,7 @@ protected function getJsonAsArray(string $jsonString): mixed
*
* @return mixed|null
*/
- protected function getJsonAsObject(string $jsonString): mixed
+ protected function getJsonAsObject(string $jsonString)
{
try {
return json_decode($jsonString, false, 512, JSON_THROW_ON_ERROR);