Skip to content
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

Feature/add laravel 11 support and improve test quality #35

Merged
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
63 changes: 25 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ name: "CI Tests"
on:
pull_request:
push:
branches:
- main

jobs:
php81:
name: PHP 8.1
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -20,22 +22,17 @@ jobs:
php-version: "8.1"

- name: "Cache composer packages"
uses: "actions/cache@v3"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-composer-locked-"
path: "vendor"
key: "php-composer-locked-php-8.1-${{ hashFiles('**/composer.lock') }}"
restore-keys: "php-composer-locked-php-8.1-"

- name: "Install dependencies with composer"
run: "composer install --no-interaction --prefer-dist"

- name: "Run PHPUnit Tests"
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer test
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v
run: "composer test-coverage"

- name: "Run PHP CS Check"
run: "composer cs-check"
Expand All @@ -50,16 +47,14 @@ jobs:
run: "composer lint"

- name: "Run infection"
env:
INFECTION_BADGE_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
run: "composer infection"
run: "composer infection-ci"

php82:
name: PHP 8.2
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -69,22 +64,17 @@ jobs:
php-version: "8.2"

- name: "Cache composer packages"
uses: "actions/cache@v3"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-composer-locked-"
path: "vendor"
key: "php-composer-locked-php-8.2-${{ hashFiles('**/composer.lock') }}"
restore-keys: "php-composer-locked-php-8.2-"

- name: "Install dependencies with composer"
run: "composer install --no-interaction --prefer-dist"

- name: "Run PHPUnit Tests"
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer test
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v
run: "composer test-coverage"

- name: "Run PHP CS Check"
run: "PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check"
Expand All @@ -99,14 +89,14 @@ jobs:
run: "composer lint"

- name: "Run infection"
run: "composer infection"
run: "composer infection-ci"

php83:
name: PHP 8.3
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -116,22 +106,17 @@ jobs:
php-version: "8.3"

- name: "Cache composer packages"
uses: "actions/cache@v3"
uses: "actions/cache@v4"
with:
path: "~/.composer/cache"
key: "php-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-composer-locked-"
path: "vendor"
key: "php-composer-locked-php-8.3-${{ hashFiles('**/composer.lock') }}"
restore-keys: "php-composer-locked-php-8.3-"

- name: "Install dependencies with composer"
run: "composer install --no-interaction --prefer-dist"

- name: "Run PHPUnit Tests"
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer test
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/output/tests/coverage.xml --json_path=build/output/tests/coveralls-upload.json -v
run: "composer test-coverage"

- name: "Run PHP CS Check"
run: "PHP_CS_FIXER_IGNORE_ENV=1 composer cs-check"
Expand All @@ -146,4 +131,6 @@ jobs:
run: "composer lint"

- name: "Run infection"
run: "composer infection"
env:
INFECTION_BADGE_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
run: "composer infection-ci"
27 changes: 5 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
/vendor/
node_modules/
npm-debug.log
yarn-error.log

# Laravel 4 specific
bootstrap/compiled.php
app/storage/

# Laravel 5 & Lumen specific
public/storage
public/hot

# Laravel 5 & Lumen specific with changed public path
public_html/storage
public_html/hot

storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
# PHPUnit specific
.phpunit.result.cache

# Composer
/vendor/
composer.lock

# Package specific
/tmp
/build
/tests/Http/Responses/metadata
4 changes: 2 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'magic_constant_casing' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'new_with_parentheses' => true,
'no_alternative_syntax' => true,
'no_closing_tag' => true,
'no_empty_comment' => true,
Expand All @@ -41,7 +41,7 @@
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_braces' => true,
'no_unneeded_final_method' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ You are also welcome to use the Issue Tracker to set bugs, improvements or upgra
``` composer require dropelikeit/laravel-jms-serializer ```

### Support note
- Laravel 6 and 7 are no longer supported with release v4.0.0 and higher.
- Laravel 5.* is no longer supported with release v2.0.0 and higher.
| Laravel | PHP | Package Version | Status |
|:-------:|:------------------:|:---------------:|:-------------:|
| 11 | 8.2, 8.3 | v6.x.x | Support |
| 10 | 8.1, 8.2, 8.3 | >=v5.x.x | Support |
| 9 | 8.0, 8.1, 8.2 | v4.x.x - v5.1.0 | Not supported |
| 8 | 7.3, 7.4, 8.0, 8.1 | v3.x.x - v4.0.0 | Not supported |
| 7 | 7.2, 7.3, 7.4, 8.0 | v2.x.x - v3.0.0 | Not supported |
| 6 | 7.2, 7.3, 7.4, 8.0 | v1.x.x - v3.0.0 | Not supported |

### How to use

Expand Down
31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
}
],
"require": {
"php": "^8.1",
"illuminate/http": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0",
"jms/serializer": "^3.27"
"php": "^8.1|^8.2|^8.3",
"illuminate/http": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"jms/serializer": "^3.30"
},
"autoload": {
"psr-4": {
Expand All @@ -37,27 +37,28 @@
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"friendsofphp/php-cs-fixer": "^3.23",
"phpunit/phpunit": "^10.3",
"nunomaduro/larastan": "^2.6",
"orchestra/testbench": "^8.9",
"friendsofphp/php-cs-fixer": "^3.52",
"phpunit/phpunit": "^10.0",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^8.9|^9.0",
"phpstan/phpstan-phpunit": "^1.3",
"php-parallel-lint/php-parallel-lint": "^1.3",
"symfony/cache": "^6.3",
"vimeo/psalm": "^5.15",
"psalm/plugin-laravel": "^2.8",
"psalm/plugin-phpunit": "^0.18.4",
"infection/infection": "^0.27.6"
"symfony/cache": "^6.3|^7.0",
"vimeo/psalm": "^5.23",
"psalm/plugin-laravel": "^2.10",
"psalm/plugin-phpunit": "^0.19",
"infection/infection": "^0.27.10"
},
"scripts": {
"lint": "parallel-lint --exclude .git --exclude vendor .",
"cs-check": "php-cs-fixer -v --dry-run --using-cache=no fix",
"cs-fix": "php-cs-fixer --using-cache=no fix",
"test": "export XDEBUG_MODE=coverage && phpunit",
"test-coverage": "export XDEBUG_MODE=coverage && phpunit --coverage-clover build/logs/clover.xml --coverage-html build/logs/clover.html",
"test-coverage": "export XDEBUG_MODE=coverage && phpunit --coverage-xml build/logs --coverage-clover build/logs/clover.xml --coverage-html build/logs/clover.html --log-junit build/logs/junit.xml",
"analyze": "phpstan analyze --no-progress --memory-limit=-1 --xdebug",
"psalm": "psalm --no-cache -c psalm.xml",
"infection": "infection --threads=4",
"infection-ci": "infection --coverage=build/logs --threads=4",
"check": [
"@cs-check",
"@analyze",
Expand Down
10 changes: 5 additions & 5 deletions infection.json5
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"@default": true
},
"logs": {
"html": "infection.html",
"summary": "summary.log",
"json": "infection-log.json",
"perMutator": "per-mutator.md",
"html": "build/infection/infection.html",
"summary": "build/infection/summary.log",
"json": "build/infection/infection-log.json",
"perMutator": "build/infection/per-mutator.md",
"github": true,
"stryker": {
"badge": "master"
},
"summaryJson": "summary.json"
"summaryJson": "build/infection/summary.json"
},
}
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor/larastan/larastan/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Responses/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
final class ResponseFactory implements Contracts\ResponseBuilder
{
private const HEADER_NAME_CONTENT_TYPE = 'Content-Type';
private const HEADER_VALUE_APPLICATION_JSON = 'application/json';
private const HEADER_VALUE_APPLICATION_XML = 'application/xml';
private const SERIALIZER_INITIAL_TYPE_ARRAY = 'array';

Expand Down Expand Up @@ -129,7 +128,6 @@ private function getResponse(string $content): Response
return new JsonResponse(
data: $content,
status: $this->status,
headers: [self::HEADER_NAME_CONTENT_TYPE => self::HEADER_VALUE_APPLICATION_JSON],
json: true
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
use Dropelikeit\LaravelJmsSerializer\Serializer\Factory;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use function sprintf;
Expand Down Expand Up @@ -64,9 +65,11 @@ public function register(): void

$this->app->bind(ResponseBuilder::class, ResponseFactory::class);

$app = $this->app;
$this->app->bind('ResponseFactory', static function ($app): ResponseFactory {
return $app->get(ResponseFactory::class);
$this->app->bind('ResponseFactory', static function (Application $app): ResponseFactory {
$responseFactory = $app->get(ResponseFactory::class);
Assert::isInstanceOf($responseFactory, ResponseFactory::class);

return $responseFactory;
});
}

Expand Down
Loading