Skip to content
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
48 changes: 41 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,51 @@ jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [8.2, 8.3, 8.4, 8.5]
laravel: [10.*, 11.*, 12.*]
include:
- laravel: 10.*
testbench: ^8.0
phpunit: ^10.0
- laravel: 11.*
testbench: ^9.0
phpunit: ^10.5
- laravel: 12.*
testbench: ^10.0
phpunit: ^11.0
exclude:
# Laravel 10 doesn't support PHP 8.4
- php: 8.4
laravel: 10.*
# Only Laravel 12 supports PHP 8.5
- php: 8.5
laravel: 10.*
- php: 8.5
laravel: 11.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- uses: actions/checkout@v3

- uses: php-actions/composer@v6

- name: PHPUnit Tests
uses: php-actions/phpunit@master
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
version: 9.6
bootstrap: vendor/autoload.php
configuration: ./phpunit.xml
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer require "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" --dev --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit

lint:
runs-on: ubuntu-latest
Expand Down
15 changes: 14 additions & 1 deletion src/Resources/JsonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ public function toArray($request): array
: $this->addToResponse($request, $this->getResourceData($request));
}

/**
* Resolve the resource data to an array.
*
* Override Laravel 12's implementation to prevent circular dependency
* between toArray() and toAttributes().
*/
public function resolveResourceData($request): array
{
return is_null($this->resource)
? []
: $this->addToResponse($request, $this->getResourceData($request));
}

/**
* Returns the value of $this->data and sets it if it's empty.
*/
Expand Down Expand Up @@ -172,7 +185,7 @@ protected function getType(): string
* Default to either `registerData['attributes']` or an empty array.
* Should be overwritten to create custom attributes.
*/
protected function toAttributes(Request $request): array
public function toAttributes(Request $request): array
{
return $this->registerData['attributes'] ?? [];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/DeveloperResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DeveloperResource extends JsonApiResource
{
protected string $type = 'developers';

protected function toAttributes(Request $request): array
public function toAttributes(Request $request): array
{
return [
'name' => $this->resource->name,
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/InternResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InternResource extends JsonApiResource
{
protected string $type = 'interns';

protected function toAttributes(Request $request): array
public function toAttributes(Request $request): array
{
return [
'name' => $this->resource->name,
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/PullRequestResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PullRequestResource extends JsonApiResource
{
protected string $type = 'pull_requests';

protected function toAttributes(Request $request): array
public function toAttributes(Request $request): array
{
return [
'title' => $this->resource->title,
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/ReviewResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ReviewResource extends JsonApiResource
{
protected string $type = 'reviews';

protected function toAttributes(Request $request): array
public function toAttributes(Request $request): array
{
return [
'content' => $this->resource->content,
Expand Down
Loading