From ec194b9473b98f1a4ea0ac4dfe6fc7a35661c075 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 14:59:29 +0200 Subject: [PATCH 1/7] Laravel 11.x Compatibility --- .github/workflows/phpstan.yml | 2 +- .github/workflows/run-tests.yml | 16 +++-- .gitignore | 2 + LICENSE.md | 2 +- composer.json | 27 +++++---- phpunit.xml.dist | 58 +++++++------------ src/Http/Controllers/NpsAnswerController.php | 13 +++-- .../Controllers/NpsAnswerDelayController.php | 11 ++-- src/Http/Controllers/NpsController.php | 9 +-- src/NpsFinder.php | 1 + 10 files changed, 64 insertions(+), 77 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 4f3f936..3855a08 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' coverage: none - name: Install composer dependencies diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 59d59f1..b7ed222 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,19 +13,17 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.3, 8.2, 8.1, 8.0] - laravel: [10.*, 9.*] + php: [8.3, 8.2, 8.1] + laravel: [11.*, 10.*,] stability: [prefer-lowest, prefer-stable] include: + - laravel: 11.* + testbench: 9.* - laravel: 10.* testbench: 8.* - carbon: ^2.63 - - laravel: 9.* - testbench: 7.* - carbon: ^2.63 exclude: - - laravel: 10.* - php: 8.0 + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -47,7 +45,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests diff --git a/.gitignore b/.gitignore index 9a43686..e80aa49 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ testbench.yaml vendor node_modules .php-cs-fixer.cache +.phpunit.cache +.phpunit.cache/test-results diff --git a/LICENSE.md b/LICENSE.md index 43c44ab..3b09b56 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2023 MAIZE SRL +Copyright (c) 2024 MAIZE SRL Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index b005544..89ccb8b 100644 --- a/composer.json +++ b/composer.json @@ -21,25 +21,24 @@ } ], "require": { - "php": "^8.0", - "illuminate/database": "^9.0|^10.0", - "illuminate/http": "^9.0|^10.0", - "illuminate/routing": "^9.0|^10.0", - "illuminate/support": "^9.0|^10.0", - "illuminate/validation": "^9.0|^10.0", + "php": "^8.1", + "illuminate/database": "^10.0|^11.0", + "illuminate/http": "^10.0|^11.0", + "illuminate/routing": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "illuminate/validation": "^10.0|^11.0", "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4", - "nunomaduro/collision": "^6.0", - "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^7.0|^8.0", - "pestphp/pest": "^1.21", - "pestphp/pest-plugin-laravel": "^1.1", - "phpstan/extension-installer": "^1.1", + "nunomaduro/collision": "^7.10.0|^8.1.1", + "larastan/larastan": "^2.0.1", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-laravel": "^2.3", + "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-phpunit": "^1.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 290f954..10a8150 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,39 +1,23 @@ - - - - tests - - - - - ./src - - - - - - - - - - + + + + tests + + + + + + + + + + + + + + + ./src + + diff --git a/src/Http/Controllers/NpsAnswerController.php b/src/Http/Controllers/NpsAnswerController.php index 538a1c9..48edead 100644 --- a/src/Http/Controllers/NpsAnswerController.php +++ b/src/Http/Controllers/NpsAnswerController.php @@ -10,12 +10,13 @@ class NpsAnswerController extends Controller { public function __invoke(NpsAnswerRequest $request, $id) { - $request - ->user() - ->answerNps( - Nps::findOrFail($id), - $request->validated() - ); + $user = $request->user(); + + /** @phpstan-ignore-next-line */ + $user->answerNps( + Nps::findOrFail($id), + $request->validated() + ); return response()->noContent(); } diff --git a/src/Http/Controllers/NpsAnswerDelayController.php b/src/Http/Controllers/NpsAnswerDelayController.php index b4a1160..c474809 100644 --- a/src/Http/Controllers/NpsAnswerDelayController.php +++ b/src/Http/Controllers/NpsAnswerDelayController.php @@ -10,11 +10,12 @@ class NpsAnswerDelayController extends Controller { public function __invoke(Request $request, $id) { - $request - ->user() - ->delayNps( - Nps::findOrFail($id), - ); + $user = $request->user(); + + /** @phpstan-ignore-next-line */ + $user->delayNps( + Nps::findOrFail($id), + ); return response()->noContent(); } diff --git a/src/Http/Controllers/NpsController.php b/src/Http/Controllers/NpsController.php index b552512..a8b1eb0 100644 --- a/src/Http/Controllers/NpsController.php +++ b/src/Http/Controllers/NpsController.php @@ -10,10 +10,11 @@ class NpsController extends Controller { public function __invoke(Request $request) { - $nps = $request - ->user() - ->findCurrentNps(true); + $nps = $request->user(); - return new NpsResource($nps); + /** @phpstan-ignore-next-line */ + $nps->findCurrentNps(true); + + return NpsResource::make($nps); } } diff --git a/src/NpsFinder.php b/src/NpsFinder.php index 4e3cfda..dc90711 100644 --- a/src/NpsFinder.php +++ b/src/NpsFinder.php @@ -16,6 +16,7 @@ public function find(bool $fail = false): ?Nps $model = $this->getNpsModel(); $builder = $model::query(); + /** @var ?Nps $nps */ $nps = Cache::remember( $model::npsCacheKey(), config('nps.cache.nps_ttl'), From 1ff62a7d27d3d13fbb53b854155127f043d61961 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 15:03:06 +0200 Subject: [PATCH 2/7] Laravel 11.x Compatibility --- src/Http/Controllers/NpsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Controllers/NpsController.php b/src/Http/Controllers/NpsController.php index a8b1eb0..7164efc 100644 --- a/src/Http/Controllers/NpsController.php +++ b/src/Http/Controllers/NpsController.php @@ -10,10 +10,10 @@ class NpsController extends Controller { public function __invoke(Request $request) { - $nps = $request->user(); + $user = $request->user(); /** @phpstan-ignore-next-line */ - $nps->findCurrentNps(true); + $nps = $user->findCurrentNps(true); return NpsResource::make($nps); } From 00a52881bfc1533aa75507e27dc65a8a668bf29d Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 15:10:54 +0200 Subject: [PATCH 3/7] Laravel 11.x Compatibility --- tests/NpsTest.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/NpsTest.php b/tests/NpsTest.php index 2e4f736..8cd6d3d 100644 --- a/tests/NpsTest.php +++ b/tests/NpsTest.php @@ -4,7 +4,9 @@ use Maize\Nps\Models\Nps; use Maize\Nps\Tests\Models\User; -test('can get a nps', function (User $user) { +test('can get a nps', function () { + $user = User::factory()->create(); + $nps = Nps::factory()->create([ 'starts_at' => now()->subDays(2), 'ends_at' => now()->addDays(2), @@ -19,9 +21,12 @@ 'question' => $nps->question, ], ]); -})->with('user'); +}); + +test('cannot get a ended nps', function () { + + $user = User::factory()->create(); -test('cannot get a ended nps', function (User $user) { Nps::factory()->create([ 'starts_at' => now()->subDays(4), 'ends_at' => now()->subDays(2), @@ -30,9 +35,11 @@ actingAs($user, 'api') ->getJson(routeByPartialName('nps.show')) ->assertStatus(404); -})->with('user'); +}); + +test('cannot get a not started nps', function () { + $user = User::factory()->create(); -test('cannot get a not started nps', function (User $user) { Nps::factory()->create([ 'starts_at' => now()->addDays(4), 'ends_at' => now()->addDays(2), @@ -41,7 +48,7 @@ actingAs($user, 'api') ->getJson(routeByPartialName('nps.show')) ->assertStatus(404); -})->with('user'); +}); test('can get current nps', function (User $user, Nps $nps) { Nps::factory()->create([ From 0082c82d717d99e7c6dba1b8c64f33aa5f3fa2e4 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 15:16:13 +0200 Subject: [PATCH 4/7] Laravel 11.x Compatibility --- tests/NpsTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/NpsTest.php b/tests/NpsTest.php index 8cd6d3d..10aa9dc 100644 --- a/tests/NpsTest.php +++ b/tests/NpsTest.php @@ -50,7 +50,9 @@ ->assertStatus(404); }); -test('can get current nps', function (User $user, Nps $nps) { +test('can get current nps', function (Nps $nps) { + $user = User::factory()->create(); + Nps::factory()->create([ 'starts_at' => null, 'ends_at' => null, @@ -89,9 +91,11 @@ 'id' => $nps->getKey(), ], ]); -})->with('user', 'current_nps'); +})->with('current_nps'); + +test('nps should be cached', function (Nps $nps) { + $user = User::factory()->create(); -test('nps should be cached', function (User $user, Nps $nps) { actingAs($user, 'api') ->getJson(routeByPartialName('nps.show')) ->assertStatus(200); @@ -103,4 +107,4 @@ expect( Cache::get(Nps::npsCacheKey())->toArray() )->toMatchArray($nps->toArray()); -})->with('user', 'current_nps'); +})->with('current_nps'); From 1b34a091fe823f162d008b78559ab6215e3b7a0a Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 15:18:11 +0200 Subject: [PATCH 5/7] Laravel 11.x Compatibility --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b7ed222..981f0cb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,10 +12,10 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] /*, windows-latest*/ php: [8.3, 8.2, 8.1] laravel: [11.*, 10.*,] - stability: [prefer-lowest, prefer-stable] + stability: [prefer-stable] /*prefer-lowest, */ include: - laravel: 11.* testbench: 9.* From d49ac4ed1263137e427cd489e2b20ed3839286c4 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 15:19:54 +0200 Subject: [PATCH 6/7] Laravel 11.x Compatibility --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 981f0cb..a0b35a2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,10 +12,10 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest] /*, windows-latest*/ + os: [ubuntu-latest] #, windows-latest php: [8.3, 8.2, 8.1] laravel: [11.*, 10.*,] - stability: [prefer-stable] /*prefer-lowest, */ + stability: [prefer-stable] #prefer-lowest, include: - laravel: 11.* testbench: 9.* From 9e8c330ee9141bdf8be1d9e11a33e05628a3f831 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Fri, 19 Apr 2024 15:21:12 +0200 Subject: [PATCH 7/7] Laravel 11.x Compatibility --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a0b35a2..436e527 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest] #, windows-latest + os: [ubuntu-latest, windows-latest] php: [8.3, 8.2, 8.1] laravel: [11.*, 10.*,] stability: [prefer-stable] #prefer-lowest,