From 98a4234df31881e874e3cb6942571452cd4e15f7 Mon Sep 17 00:00:00 2001 From: Norby Baruani Date: Thu, 4 Apr 2024 11:54:34 +0200 Subject: [PATCH 1/3] Add laravel 11 support --- .github/workflows/run-tests.yml | 17 ++++++++++------- composer.json | 6 +++--- phpunit.xml.dist | 1 + src/Traits/PasswordlessAuth.php | 4 ++-- tests/TestCase.php | 8 +------- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b72bf48..4f2ed7e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,15 +15,18 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1] - laravel: [8.*, 9.*, 10.*] + php: [8.0, 8.1, 8.2, 8.3] + laravel: [9.*, 10.*, 11.*] dependency-version: [prefer-lowest, prefer-stable] - include: - - laravel: 8.* - testbench: ^6.0 exclude: + - laravel: 9.* + php: 8.3 - laravel: 10.* php: 8.0 + - laravel: 11.* + php: 8.0 + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} @@ -45,9 +48,9 @@ jobs: with: path: ${{ steps.composer-cache.outputs.dir }} # Use composer.json for key, if composer.lock is not committed. - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: php-${{ matrix.php }}-lara-${{ matrix.laravel }}-composer-${{ matrix.dependency-version }}-${{ hashFiles('**/composer.json') }} # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- + restore-keys: php-${{ matrix.php }}-lara-${{ matrix.laravel }}-composer-${{ matrix.dependency-version }}- - name: Install Composer dependencies run: | diff --git a/composer.json b/composer.json index 868233e..2fb1dd6 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ }, "require": { "php": "^8.0", - "illuminate/support": "^8.0|^9.0|^10.0" + "illuminate/support": "^9.0|^10.0|^11.0" }, "prefer-stable": true, "require-dev": { "laravel/pint": "^1.1", "nunomaduro/larastan": "^1.0|^2.0", - "orchestra/testbench": "^6.24|^7.0|^8.0", - "phpunit/phpunit": "^9.5|^10.0" + "orchestra/testbench": "^7.0|^8.0|^9.0", + "phpunit/phpunit": "^9.5|^10.0|^11.0" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 24a654b..f144180 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,5 +18,6 @@ + diff --git a/src/Traits/PasswordlessAuth.php b/src/Traits/PasswordlessAuth.php index a87bd38..45681da 100644 --- a/src/Traits/PasswordlessAuth.php +++ b/src/Traits/PasswordlessAuth.php @@ -31,8 +31,8 @@ public function loginByEmail(Request $request): RedirectResponse|Response } return redirect()->to($this->redirectRoute($request, false)) - ->withInput($request->only('email')) - ->withErrors(['email' => trans($response)]); + ->withInput($request->only('email')) + ->withErrors(['email' => trans($response)]); } $this->authenticateUser($response); diff --git a/tests/TestCase.php b/tests/TestCase.php index 2c02d04..14bdfc0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -42,12 +42,6 @@ protected function defineRoutes($router) */ protected function defineEnvironment($app) { - $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'prefix' => '', - ]); $app['config']->set('auth.providers.users.model', User::class); } @@ -58,7 +52,7 @@ protected function defineEnvironment($app) */ protected function defineDatabaseMigrations() { - $this->loadLaravelMigrations(); + $this->loadMigrationsFrom(base_path('migrations')); $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } From de8bd3757d9ac1724bf2ebe8aa8b4f0e1f09ff85 Mon Sep 17 00:00:00 2001 From: Norby Baruani Date: Thu, 4 Apr 2024 12:08:53 +0200 Subject: [PATCH 2/3] fix test --- composer.json | 2 +- tests/Feature/LoginFeatureTest.php | 11 ----------- tests/Feature/MagicLinkFeatureTest.php | 16 ---------------- tests/TestCase.php | 13 +++++++++++++ 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 2fb1dd6..9c1c303 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ }, "require": { "php": "^8.0", - "illuminate/support": "^9.0|^10.0|^11.0" + "illuminate/support": "^9.5|^10.0|^11.0" }, "prefer-stable": true, "require-dev": { diff --git a/tests/Feature/LoginFeatureTest.php b/tests/Feature/LoginFeatureTest.php index e4ad790..4c7438a 100644 --- a/tests/Feature/LoginFeatureTest.php +++ b/tests/Feature/LoginFeatureTest.php @@ -5,10 +5,7 @@ use Carbon\Carbon; use Illuminate\Routing\Exceptions\InvalidSignatureException; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Str; use NorbyBaru\Passwordless\Facades\Passwordless; -use NorbyBaru\Passwordless\Tests\Fixtures\Models\User as UserModel; use NorbyBaru\Passwordless\Tests\TestCase; class LoginFeatureTest extends TestCase @@ -19,14 +16,6 @@ public function setUp(): void { parent::setUp(); - $this->user = UserModel::create([ - 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => Hash::make(Str::random(10)), - 'remember_token' => Str::random(10), - ]); - $token = Passwordless::magicLink()->createToken($this->user); $this->signedUrl = Passwordless::magicLink()->generateUrl($this->user, $token); } diff --git a/tests/Feature/MagicLinkFeatureTest.php b/tests/Feature/MagicLinkFeatureTest.php index 0366f2e..1f7f127 100644 --- a/tests/Feature/MagicLinkFeatureTest.php +++ b/tests/Feature/MagicLinkFeatureTest.php @@ -4,7 +4,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Carbon; -use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Str; use NorbyBaru\Passwordless\Facades\Passwordless; @@ -15,21 +14,6 @@ class MagicLinkFeatureTest extends TestCase { - protected UserModel $user; - - public function setUp(): void - { - parent::setUp(); - - $this->user = UserModel::create([ - 'name' => $this->faker->name, - 'email' => $this->faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => Hash::make(Str::random(10)), - 'remember_token' => Str::random(10), - ]); - } - public function test_it_can_generate_magic_link() { $token = Passwordless::magicLink()->createToken($this->user); diff --git a/tests/TestCase.php b/tests/TestCase.php index 14bdfc0..08d42e9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,9 +4,12 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Str; use NorbyBaru\Passwordless\PasswordlessServiceProvider; use NorbyBaru\Passwordless\Tests\Fixtures\Models\User; +use NorbyBaru\Passwordless\Tests\Fixtures\Models\User as UserModel; use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class TestCase extends OrchestraTestCase @@ -14,11 +17,21 @@ abstract class TestCase extends OrchestraTestCase use RefreshDatabase; use WithFaker; + protected UserModel $user; + public function setUp(): void { parent::setUp(); $this->setUpFaker(); Notification::fake(); + + $this->user = UserModel::create([ + 'name' => $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'email_verified_at' => now(), + 'password' => Hash::make(Str::random(10)), + 'remember_token' => Str::random(10), + ]); } /** From 9207a26ffb4c9095b32504ad0c3ab71f72e7cfe7 Mon Sep 17 00:00:00 2001 From: Norby Baruani Date: Thu, 4 Apr 2024 12:11:26 +0200 Subject: [PATCH 3/3] fix L9 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9c1c303..d125f1a 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ }, "require": { "php": "^8.0", - "illuminate/support": "^9.5|^10.0|^11.0" + "illuminate/support": "^9.52|^10.0|^11.0" }, "prefer-stable": true, "require-dev": {