Skip to content

Commit

Permalink
Add laravel 11 support (#19)
Browse files Browse the repository at this point in the history
* Add laravel 11 support

* fix test

* fix L9
  • Loading branch information
norbybaru committed Apr 4, 2024
1 parent 6901da2 commit c8aad75
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 46 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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: |
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
},
"require": {
"php": "^8.0",
"illuminate/support": "^8.0|^9.0|^10.0"
"illuminate/support": "^9.52|^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"
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<php>
<env name="APP_ENV" value="testing" force="true"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
4 changes: 2 additions & 2 deletions src/Traits/PasswordlessAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions tests/Feature/LoginFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
16 changes: 0 additions & 16 deletions tests/Feature/MagicLinkFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
21 changes: 14 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@

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
{
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),
]);
}

/**
Expand All @@ -42,12 +55,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);
}

Expand All @@ -58,7 +65,7 @@ protected function defineEnvironment($app)
*/
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();
$this->loadMigrationsFrom(base_path('migrations'));
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}

Expand Down

0 comments on commit c8aad75

Please sign in to comment.