Skip to content

Commit

Permalink
Merge pull request #6 from timacdonald/dev-tools
Browse files Browse the repository at this point in the history
php 8.1 support
  • Loading branch information
timacdonald authored Dec 10, 2021
2 parents 14cb189 + 254cdb9 commit 851c54f
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 20 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
key: dependencies-composer-${{ hashFiles('composer.json') }}-v3

- name: Install dependencies
run: composer install --no-suggest --no-interaction --verbose
run: |
composer update --no-suggest --no-interaction --verbose
- name: Check platform requirements
run: composer check-platform-reqs --verbose
Expand Down Expand Up @@ -61,7 +62,7 @@ jobs:
name: 'Test suite on PHP: ${{ matrix.php }}; Dependecies: ${{ matrix.dependency-version }}'
strategy:
matrix:
php: ['7.4', '8.0']
php: ['7.4', '8.0', '8.1']
dependency-version: ['prefer-lowest', 'prefer-stable']

steps:
Expand All @@ -82,9 +83,12 @@ jobs:

- name: Install dependencies
run: |
composer remove 'friendsofphp/php-cs-fixer' 'infection/infection' 'nunomaduro/larastan' 'phpstan/phpstan' 'phpunit/phpunit' 'ergebnis/composer-normalize' --dev --no-update --no-interaction --verbose
composer update --${{ matrix.dependency-version }} --no-suggest --no-interaction --verbose
- name: Support prefer-lowest in PHP 8.1
if: ${{ matrix.php == 8.1 && matrix.dependency-version == 'prefer-lowest' }}
run: composer require symfony/console:">=5.3.7" symfony/http-foundation:">=5.3.7" laravel/framework:">=8.62.0" nesbot/carbon:">=2.51.0" ramsey/collection:">=1.2.0" --prefer-lowest --with-all-dependencies

- name: Check platform requirements
run: composer check-platform-reqs --verbose

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ A lightweight JSON Resource for Laravel that helps you adhere to the JSON:API st

These docs are not designed to introduce you to the JSON:API spec and the associated concepts, instead you should [head over and read the spec](https:/jsonapi.org) if you are not familiar with it.

# Version support

- **PHP**: 7.4, 8.0, 8.1
- **Laravel**: 8.0

# Installation

You can install using [composer](https://getcomposer.org/) from [Packagist](https://packagist.org/packages/timacdonald/json-api).

```
$ composer require timacdonald/json-api
```sh
composer require timacdonald/json-api
```

# Basic usage
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
"laravel/framework": "^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"infection/infection": "^0.25.4",
"nunomaduro/larastan": "^0.7.12",
"orchestra/testbench": "^6.0",
"phpstan/phpstan": "^0.12.94",
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.3.3"
"bamarni/composer-bin-plugin": "^1.4"
},
"config": {
"preferred-install": "dist",
Expand All @@ -45,6 +39,13 @@
"minimum-stability": "stable",
"prefer-stable": true,
"scripts": {
"bin": "echo 'bin not installed'",
"post-install-cmd": [
"@composer bin all install --ansi"
],
"post-update-cmd": [
"@composer bin all update --ansi"
],
"fix": [
"clear",
"@composer normalize",
Expand Down
5 changes: 2 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
parameters:
level: max
level: 8
paths:
- src
- tests
checkInternalClassCaseSensitivity: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
checkMissingIterableValueType: false
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor-bin/linting/vendor/nunomaduro/larastan/extension.neon
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="./vendor-bin/testing/vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait Attributes
*/
public static function maximalAttributes(): void
{
static::$minimalAttributes = false;
self::$minimalAttributes = false;
}

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ private function fields(Request $request): ?array
return $fields;
}

return static::$minimalAttributes
return self::$minimalAttributes
? []
: null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function resolveTypeUsing(Closure $resolver): void

public static function minimalAttributes(): void
{
static::$minimalAttributes = true;
self::$minimalAttributes = true;
}

protected function toAttributes(Request $request): array
Expand Down
10 changes: 10 additions & 0 deletions tests/Models/BasicModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
namespace Tests\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;

/**
* @property string $content
* @property string $key
* @property string $name
* @property string $title
* @property string $url
* @property array $posts
* @property self $author
* @property self $license
* @property self $feature_image
* @property self $avatar
* @property self|array $child
* @property self $post
* @property self $user
* @property Collection<self> $likes
* @property Collection<self> $comments
*/
class BasicModel extends Model
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Resources/BasicJsonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use TiMacDonald\JsonApi\JsonApiResource;

/**
* @mixin \Tests\Models\BasicModel
*/
class BasicJsonApiResource extends JsonApiResource
{
//
Expand Down
3 changes: 3 additions & 0 deletions tests/Resources/CommentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Http\Request;
use TiMacDonald\JsonApi\JsonApiResource;

/**
* @mixin \Tests\Models\BasicModel
*/
class CommentResource extends JsonApiResource
{
protected function toAttributes(Request $request): array
Expand Down
3 changes: 3 additions & 0 deletions tests/Resources/ImageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Http\Request;
use TiMacDonald\JsonApi\JsonApiResource;

/**
* @mixin \Tests\Models\BasicModel
*/
class ImageResource extends JsonApiResource
{
protected function toAttributes(Request $request): array
Expand Down
5 changes: 4 additions & 1 deletion tests/Resources/LicenseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Http\Request;
use TiMacDonald\JsonApi\JsonApiResource;

/**
* @mixin \Tests\Models\BasicModel
*/
class LicenseResource extends JsonApiResource
{
protected function toAttributes(Request $request): array
Expand All @@ -19,7 +22,7 @@ protected function toAttributes(Request $request): array
protected function toRelationships(Request $request): array
{
return [
'user' => UserResource::make($this->user),
'user' => fn () => UserResource::make($this->user),
];
}
}
3 changes: 3 additions & 0 deletions tests/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Http\Request;
use TiMacDonald\JsonApi\JsonApiResource;

/**
* @mixin \Tests\Models\BasicModel
*/
class PostResource extends JsonApiResource
{
protected function toAttributes(Request $request): array
Expand Down
3 changes: 3 additions & 0 deletions tests/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use TiMacDonald\JsonApi\JsonApiResource;
use TiMacDonald\JsonApi\JsonApiResourceCollection;

/**
* @mixin \Tests\Models\BasicModel
*/
class UserResource extends JsonApiResource
{
protected function toAttributes(Request $request): array
Expand Down
7 changes: 7 additions & 0 deletions vendor-bin/linting/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"nunomaduro/larastan": "^1.0",
"friendsofphp/php-cs-fixer": "^3.3",
"orchestra/testbench": "^6.0"
}
}
8 changes: 8 additions & 0 deletions vendor-bin/testing/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"phpunit/phpunit": "^9.5",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^6.0",
"infection/infection": "^0.25.4"
}
}

0 comments on commit 851c54f

Please sign in to comment.