Skip to content

Commit

Permalink
Feature/add laravel 11 support and improve test quality (#35)
Browse files Browse the repository at this point in the history
* Updating dependencies and refactoring ResponseFactoryTest and Serializer/FactoryTest

This commit updates the version numbers of several dependencies in composer.json and performs a significant refactoring of ResponseFactoryTest and Serializer/FactoryTest. The changes in ResponseFactoryTest include refactoring the test names and adding new test methods. At the same time, additional test methods were added and existing methods were revised. A new file, XmlDummy.php, is also created for testing purposes.

* Updating dependencies and refactoring ResponseFactoryTest and Serializer/FactoryTest

This commit updates the version numbers of several dependencies in composer.json and performs a significant refactoring of ResponseFactoryTest and Serializer/FactoryTest. The changes in ResponseFactoryTest include refactoring the test names and adding new test methods. At the same time, additional test methods were added and existing methods were revised. A new file, XmlDummy.php, is also created for testing purposes.

* Update php-cs-fixer version and revise support note in README

This commit increases the php-cs-fixer version in the composer.json file from "^3.51" to "^3.52". Furthermore, the support note section in the README.md file has been revised to present supported Laravel and PHP versions in a more detailed tabulated format.

* Update package versions and support status in README

The versions for Laravel 11 and 10 packages were updated in the support note section. Package version for Laravel 11 was changed to v6.x.x, and for Laravel 10 was updated to indicate it now supports versions greater than or equal to v5.x.x.

* Simplify GitHub CI workflow and update PHP version

The CI workflow in Github has been simplified by removing coverage and coveralls, and modifying the composer test command execution. The PHP version in composer.json was updated to include PHP 8.3.

* Update GitHub CI workflow and composer settings for PHP versions

The CI workflow has been updated to reflect changes in the file path and caching keys for more specific PHP versions (8.1, 8.2, 8.3). The changes were made in the composer test command execution in the .github/workflows/ci.yml file.

* Upgrade version of actions/checkout action in CI workflow

The "actions/checkout" action version has been updated from v3 to v4 in the CI workflow file (.github/workflows/ci.yml). This change applies to multiple steps in the file, making the workflow use the more recent version of the action during the Checkout process.

* Refactor tests and enhance JSON response

The tests have been restructured and json response has been enhanced. All test-related things within the "ResponseFactory" directory have been moved to a new "data" directory. Also, the composer.json file and ServiceProvider.php have been updated with new dependencies and adjustments. Updates to ResponseFactoryTest.php now allow JSON responses as well.

* Update .gitignore file

The .gitignore file was modified to optimize it for the project's current needs. Unnecessary Laravel specific ignores were removed and PHPUnit, Composer, and Package specific ignores were added. This change will ensure that irrelevant files are not tracked by the version control system.

* Fix deprecation issues

* Remove unused code and update tests

The commit involves the removal of several unused lines of constants and code from ResponseFactory and composer.json. In addition, tests have also been updated to assert the instance type of ResponseFactory whenever it's gotten from the application container. Improvements were made to the type annotations in the ResponseFactory tests for clarity.

* Upgrade actions/cache to v4 in CI workflow

The CI workflow has been updated to use the latest version of actions/cache (v4) for caching composer packages. This change was made in the configurations for PHP versions 8.1, 8.2, and 8.3 to ensure consistent usage of the updated cache action across all versions.

* Update composer and CI workflow for better test coverage

Updated composer.json to enhance PHPUnit test coverage options and added 'infection-ci' for CI testing. Modified CI workflow to use 'infection-ci' for more efficient infection testing across different PHP versions.

* Update test command in CI workflow

The command for running tests in the CI workflow file has been changed from "composer test" to "composer test-coverage". This will aid in providing more detailed test coverage reports during the continuous integration process, thus helping in identifying untested areas of code and improving overall code quality and reliability.

* Add CI trigger for main branch

An addition was made to the CI workflow file to include triggers on push events to the main branch. Providing continuous integration support for the main branch will help ensure code stability and quality.

* Simplify PHPUnit Tests in GitHub Actions

The commit removes the Coveralls report generation from the GitHub Actions workflow. Now, the workflow only executes the test coverage without performing the extra steps for Coveralls report generation. This streamlines the GitHub Actions process by reducing complex steps.

* Update thread count for infection-ci in composer.json

Reduced the number of threads used by the 'infection-ci' command in the composer.json file. The change decreases the thread usage from 16 to 4, which may impact the execution speed but helps to reduce resource consumption.
  • Loading branch information
Dropelikeit committed May 13, 2024
1 parent b554572 commit 1b444d2
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 136 deletions.
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

0 comments on commit 1b444d2

Please sign in to comment.