diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5ec7587..92ec8ee 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -21,6 +21,8 @@ jobs: exclude: - php_version: '8.1' laravel_version: '^11.0' + - php_version: '8.1' + laravel_version: '^12.0' steps: diff --git a/composer.json b/composer.json index ebc54a7..2677eb3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "illuminate/support": "^9.0|^10.0|^11.0|^12.0" }, "require-dev": { - "phpunit/phpunit": "^9.0|^10.0", + "phpunit/phpunit": "^9.0|^10.0|^11.0|^12.0", "orchestra/testbench": "^7.5|^8.0|^9.0|^10.0", "phpstan/phpstan": "^1.9.18" }, diff --git a/tests/Unit/Descriptors/DescriptorsTraitTest.php b/tests/Unit/Descriptors/DescriptorsTraitTest.php index d41c09e..1f89f55 100644 --- a/tests/Unit/Descriptors/DescriptorsTraitTest.php +++ b/tests/Unit/Descriptors/DescriptorsTraitTest.php @@ -17,6 +17,7 @@ use Ark4ne\JsonApi\Resources\JsonApiCollection; use Ark4ne\JsonApi\Resources\JsonApiResource; use Closure; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Test\Support\Reflect; use Test\TestCase; @@ -42,6 +43,7 @@ public static function methods() /** * @dataProvider methods */ + #[DataProvider('methods')] public function testDescriptorTrait($expected, $method, ...$args) { $mock = new class extends stdClass { diff --git a/tests/Unit/Descriptors/RelationTest.php b/tests/Unit/Descriptors/RelationTest.php index f572c08..91e8623 100644 --- a/tests/Unit/Descriptors/RelationTest.php +++ b/tests/Unit/Descriptors/RelationTest.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Http\Resources\MissingValue; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Test\app\Http\Resources\UserResource; use Test\Support\Reflect; @@ -27,6 +28,7 @@ public static function resourceProvider(): array /** * @dataProvider resourceProvider */ + #[DataProvider('resourceProvider')] public function testIncluded($model) { $stub = new RelationOne(UserResource::class, fn() => null); @@ -55,6 +57,7 @@ public function testIncluded($model) /** * @dataProvider resourceProvider */ + #[DataProvider('resourceProvider')] public function testMeta($model) { $stub = new RelationOne(UserResource::class, fn() => null); @@ -75,6 +78,7 @@ public function testMeta($model) /** * @dataProvider resourceProvider */ + #[DataProvider('resourceProvider')] public function testLinks($model) { $stub = new RelationOne(UserResource::class, fn() => null); @@ -104,9 +108,10 @@ public static function dataWhenLoaded() /** * @dataProvider dataWhenLoaded */ + #[DataProvider('dataWhenLoaded')] public function testWhenLoaded($expectedAttr, $relation, $invokedAttr) { - $mockModel = $this->getMockForAbstractClass(Model::class, mockedMethods: ['relationLoaded']); + $mockModel = $this->getMockBuilder(Model::class)->onlyMethods(['relationLoaded'])->getMock(); $mockModel->expects(self::once())->method('relationLoaded')->with($expectedAttr)->willReturn(false); $stub = new RelationOne(UserResource::class, $relation); @@ -128,6 +133,7 @@ public static function dataWhenPivotLoaded() /** * @dataProvider dataWhenPivotLoaded */ + #[DataProvider('dataWhenPivotLoaded')] public function testWhenPivotLoaded($expectedAttr, $relation, $invokedAttr) { $model = new class extends Model { @@ -144,6 +150,7 @@ public function testWhenPivotLoaded($expectedAttr, $relation, $invokedAttr) /** * @dataProvider resourceProvider */ + #[DataProvider('resourceProvider')] public function testRelationMissing($model) { $missing = RelationMissing::fromRelationship(new Relationship(UserResource::class, fn() => null)); diff --git a/tests/Unit/Descriptors/ValueTest.php b/tests/Unit/Descriptors/ValueTest.php index 4b6d73a..260843d 100644 --- a/tests/Unit/Descriptors/ValueTest.php +++ b/tests/Unit/Descriptors/ValueTest.php @@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Http\Resources\MissingValue; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Test\Support\Reflect; use Test\TestCase; @@ -89,6 +90,7 @@ public static function modelsValues() /** * @dataProvider values */ + #[DataProvider('values')] public function testConvertValue($class, $value, $excepted) { /** @var \Ark4ne\JsonApi\Descriptors\Values\Value $v */ @@ -99,6 +101,7 @@ public function testConvertValue($class, $value, $excepted) /** * @dataProvider modelsValues */ + #[DataProvider('modelsValues')] public function testValueFor($model, $class, $value, $excepted) { data_set($model, 'attr', $value); @@ -114,6 +117,7 @@ public function testValueFor($model, $class, $value, $excepted) /** * @dataProvider modelsValues */ + #[DataProvider('modelsValues')] public function testValueForWithNull($model, $class, $value, $excepted) { data_set($model, 'attr', null); @@ -126,6 +130,7 @@ public function testValueForWithNull($model, $class, $value, $excepted) /** * @dataProvider modelsValues */ + #[DataProvider('modelsValues')] public function testValueForWithNullAndNonNullable($model, $class, $value, $_, $excepted) { data_set($model, 'attr', null); @@ -144,6 +149,7 @@ public function testValueForWithNullAndNonNullable($model, $class, $value, $_, $ /** * @dataProvider models */ + #[DataProvider('models')] public function testWhenNoNull($model) { data_set($model, 'attr', null); @@ -175,6 +181,7 @@ public function testWhenAppended() /** * @dataProvider models */ + #[DataProvider('models')] public function testWhenFilled(&$model) { data_set($model, 'attr', null); @@ -191,6 +198,7 @@ public function testWhenFilled(&$model) /** * @dataProvider models */ + #[DataProvider('models')] public function testUnless(&$model) { data_set($model, 'attr', 'abc'); @@ -209,6 +217,7 @@ public function testUnless(&$model) /** * @dataProvider models */ + #[DataProvider('models')] public function testWhenInFields($model) { Fields::through('test', function () use (&$model) { diff --git a/tests/Unit/Resources/Concerns/ConditionallyLoadsAttributesTest.php b/tests/Unit/Resources/Concerns/ConditionallyLoadsAttributesTest.php index 4af60e2..617aeaa 100644 --- a/tests/Unit/Resources/Concerns/ConditionallyLoadsAttributesTest.php +++ b/tests/Unit/Resources/Concerns/ConditionallyLoadsAttributesTest.php @@ -13,6 +13,7 @@ use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\MergeValue; use Illuminate\Http\Resources\MissingValue; +use PHPUnit\Framework\Attributes\DataProvider; use Test\app\Http\Resources\UserResource; use Test\Support\Reflect; use Test\TestCase; @@ -30,6 +31,7 @@ public static function data() /** * @dataProvider data */ + #[DataProvider('data')] public function testWhenInclude($expected, $property, $query) { $request = new Request(['include' => implode(',', $query)]); @@ -47,6 +49,7 @@ public function testWhenInclude($expected, $property, $query) /** * @dataProvider data */ + #[DataProvider('data')] public function testWhenInFields($expected, $property, $query) { $request = new Request(['fields' => ['type' => implode(',', $query)]]); diff --git a/tests/Unit/Support/ArrTest.php b/tests/Unit/Support/ArrTest.php index cf3a971..87982a7 100644 --- a/tests/Unit/Support/ArrTest.php +++ b/tests/Unit/Support/ArrTest.php @@ -3,6 +3,7 @@ namespace Test\Unit\Support; use Ark4ne\JsonApi\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; use Test\TestCase; class ArrTest extends TestCase @@ -63,6 +64,7 @@ public static function mergeProvider() /** * @dataProvider mergeProvider */ + #[DataProvider('mergeProvider')] public function testMerge($expected, $base, $with) { $this->assertEquals($expected, Arr::merge($base, $with)); @@ -91,6 +93,7 @@ public static function washProvider() /** * @dataProvider washProvider */ + #[DataProvider('washProvider')] public function testWash($expected, $base) { $this->assertEquals($expected, Arr::wash($base)); @@ -118,6 +121,7 @@ public static function toArrayProvider() /** * @dataProvider toArrayProvider */ + #[DataProvider('toArrayProvider')] public function testToArray($expected, $base) { $this->assertEquals($expected, Arr::toArray($base)); diff --git a/tests/Unit/Support/FieldsTest.php b/tests/Unit/Support/FieldsTest.php index 21b1aa3..638b2dd 100644 --- a/tests/Unit/Support/FieldsTest.php +++ b/tests/Unit/Support/FieldsTest.php @@ -4,6 +4,7 @@ use Ark4ne\JsonApi\Support\Fields; use Illuminate\Http\Request; +use PHPUnit\Framework\Attributes\DataProvider; use Test\TestCase; class FieldsTest extends TestCase @@ -22,6 +23,7 @@ public static function fieldsGetProvider() /** * @dataProvider fieldsGetProvider */ + #[DataProvider('fieldsGetProvider')] public function testGet(array $query, string $type, ?array $expected) { $this->assertEquals($expected, Fields::get(new Request(['fields' => $query]), $type)); diff --git a/tests/Unit/Support/ValuesTest.php b/tests/Unit/Support/ValuesTest.php index 4189c7c..8eb53e9 100644 --- a/tests/Unit/Support/ValuesTest.php +++ b/tests/Unit/Support/ValuesTest.php @@ -7,6 +7,7 @@ use Illuminate\Http\Resources\MergeValue; use Illuminate\Http\Resources\MissingValue; use Illuminate\Http\Resources\PotentiallyMissing; +use PHPUnit\Framework\Attributes\DataProvider; use Test\TestCase; class ValuesTest extends TestCase @@ -134,6 +135,7 @@ public static function dataAttribute() /** * @dataProvider dataAttribute */ + #[DataProvider('dataAttribute')] public function testHasAttribute($data, $attribute, $expected) { $this->assertEquals($expected, Values::hasAttribute($data, $attribute)); @@ -142,6 +144,7 @@ public function testHasAttribute($data, $attribute, $expected) /** * @dataProvider dataAttribute */ + #[DataProvider('dataAttribute')] public function testGetAttribute($data, $attribute, $has, $expected) { $this->assertEquals($expected, Values::getAttribute($data, $attribute)); diff --git a/tests/Unit/Support/WithTest.php b/tests/Unit/Support/WithTest.php index 7a498e9..38f78c6 100644 --- a/tests/Unit/Support/WithTest.php +++ b/tests/Unit/Support/WithTest.php @@ -3,6 +3,7 @@ namespace Test\Unit\Support; use Ark4ne\JsonApi\Support\With; +use PHPUnit\Framework\Attributes\DataProvider; use Test\TestCase; class WithTest extends TestCase @@ -63,6 +64,7 @@ public static function mergeProvider() /** * @dataProvider mergeProvider */ + #[DataProvider('mergeProvider')] public function testMerge($expected, $base, $with) { $this->assertEquals($expected, With::merge($base, $with)); @@ -91,6 +93,7 @@ public static function washProvider() /** * @dataProvider washProvider */ + #[DataProvider('washProvider')] public function testWash($expected, $base) { $this->assertEquals($expected, With::wash($base));