Skip to content

feat: support laravel v12 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
exclude:
- php_version: '8.1'
laravel_version: '^11.0'
- php_version: '8.1'
laravel_version: '^12.0'


steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Descriptors/DescriptorsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +43,7 @@ public static function methods()
/**
* @dataProvider methods
*/
#[DataProvider('methods')]
public function testDescriptorTrait($expected, $method, ...$args)
{
$mock = new class extends stdClass {
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/Descriptors/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ public static function resourceProvider(): array
/**
* @dataProvider resourceProvider
*/
#[DataProvider('resourceProvider')]
public function testIncluded($model)
{
$stub = new RelationOne(UserResource::class, fn() => null);
Expand Down Expand Up @@ -55,6 +57,7 @@ public function testIncluded($model)
/**
* @dataProvider resourceProvider
*/
#[DataProvider('resourceProvider')]
public function testMeta($model)
{
$stub = new RelationOne(UserResource::class, fn() => null);
Expand All @@ -75,6 +78,7 @@ public function testMeta($model)
/**
* @dataProvider resourceProvider
*/
#[DataProvider('resourceProvider')]
public function testLinks($model)
{
$stub = new RelationOne(UserResource::class, fn() => null);
Expand Down Expand Up @@ -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);
Expand All @@ -128,6 +133,7 @@ public static function dataWhenPivotLoaded()
/**
* @dataProvider dataWhenPivotLoaded
*/
#[DataProvider('dataWhenPivotLoaded')]
public function testWhenPivotLoaded($expectedAttr, $relation, $invokedAttr)
{
$model = new class extends Model {
Expand All @@ -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));
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Descriptors/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -144,6 +149,7 @@ public function testValueForWithNullAndNonNullable($model, $class, $value, $_, $
/**
* @dataProvider models
*/
#[DataProvider('models')]
public function testWhenNoNull($model)
{
data_set($model, 'attr', null);
Expand Down Expand Up @@ -175,6 +181,7 @@ public function testWhenAppended()
/**
* @dataProvider models
*/
#[DataProvider('models')]
public function testWhenFilled(&$model)
{
data_set($model, 'attr', null);
Expand All @@ -191,6 +198,7 @@ public function testWhenFilled(&$model)
/**
* @dataProvider models
*/
#[DataProvider('models')]
public function testUnless(&$model)
{
data_set($model, 'attr', 'abc');
Expand All @@ -209,6 +217,7 @@ public function testUnless(&$model)
/**
* @dataProvider models
*/
#[DataProvider('models')]
public function testWhenInFields($model)
{
Fields::through('test', function () use (&$model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,7 @@ public static function data()
/**
* @dataProvider data
*/
#[DataProvider('data')]
public function testWhenInclude($expected, $property, $query)
{
$request = new Request(['include' => implode(',', $query)]);
Expand All @@ -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)]]);
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Support/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -91,6 +93,7 @@ public static function washProvider()
/**
* @dataProvider washProvider
*/
#[DataProvider('washProvider')]
public function testWash($expected, $base)
{
$this->assertEquals($expected, Arr::wash($base));
Expand Down Expand Up @@ -118,6 +121,7 @@ public static function toArrayProvider()
/**
* @dataProvider toArrayProvider
*/
#[DataProvider('toArrayProvider')]
public function testToArray($expected, $base)
{
$this->assertEquals($expected, Arr::toArray($base));
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Support/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Support/ValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Support/WithTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -91,6 +93,7 @@ public static function washProvider()
/**
* @dataProvider washProvider
*/
#[DataProvider('washProvider')]
public function testWash($expected, $base)
{
$this->assertEquals($expected, With::wash($base));
Expand Down