Skip to content

Commit bb0aa20

Browse files
authored
Merge pull request #681 from DirectoryTree/laravel-12
Add Laravel 12 Support
2 parents bf579af + 5214070 commit bb0aa20

7 files changed

+47
-77
lines changed

.github/workflows/run-tests.yml

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@ on:
88

99
jobs:
1010
run-tests:
11-
runs-on: ${{ matrix.os }}
11+
runs-on: ubuntu-latest
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
os: [ubuntu-latest]
16-
php: [8.2, 8.1]
17-
laravel: [10.*, 9.*, 8.*]
18-
dependency-version: [prefer-stable]
1915
include:
20-
- laravel: 10.*
16+
- php: 8.4
17+
laravel: 12.*
18+
testbench: 10.*
19+
20+
- php: 8.4
21+
laravel: 11.*
22+
testbench: 9.*
23+
24+
- php: 8.3
25+
laravel: 10.*
2126
testbench: 8.*
22-
- laravel: 9.*
27+
28+
- php: 8.2
29+
laravel: 9.*
2330
testbench: 7.*
24-
- laravel: 8.*
25-
testbench: 6.*
2631

27-
name: ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
32+
name: P${{ matrix.php }} - L${{ matrix.laravel }}
2833

2934
steps:
3035
- name: Checkout code
@@ -46,7 +51,7 @@ jobs:
4651
- name: Install dependencies
4752
run: |
4853
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --dev
49-
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
54+
composer update --prefer-stable --prefer-dist --no-interaction
5055
5156
- name: Execute tests
5257
run: vendor/bin/phpunit --testdox

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"ext-json": "*",
1616
"ramsey/uuid": "*",
1717
"directorytree/ldaprecord": "^v3.3",
18-
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
18+
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0"
1919
},
2020
"require-dev": {
2121
"mockery/mockery": "^1.0",
2222
"phpunit/phpunit": "^8.0|^9.0|^10.0|^11.0",
23-
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
23+
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0",
2424
"spatie/ray": "^1.28",
2525
"laravel/sanctum": "*",
2626
"laravel/pint": "^1.9"
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<?php
22

3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
35
use Illuminate\Support\Facades\DB;
46
use Illuminate\Support\Facades\Schema;
5-
use Illuminate\Database\Schema\Blueprint;
6-
use Illuminate\Database\Migrations\Migration;
77

8-
class AddLdapColumnsToUsersTable extends Migration
8+
return new class extends Migration
99
{
1010
/**
1111
* Run the migrations.
12-
*
13-
* @return void
1412
*/
15-
public function up()
13+
public function up(): void
1614
{
1715
$driver = Schema::getConnection()->getDriverName();
1816

@@ -34,10 +32,8 @@ public function up()
3432

3533
/**
3634
* Reverse the migrations.
37-
*
38-
* @return void
3935
*/
40-
public function down()
36+
public function down(): void
4137
{
4238
Schema::table('users', function (Blueprint $table) {
4339
$table->dropColumn(['guid', 'domain']);
@@ -46,13 +42,8 @@ public function down()
4642

4743
/**
4844
* Compile a compatible "unique" SQL Server index constraint.
49-
*
50-
* @param string $table
51-
* @param string $column
52-
*
53-
* @return string
5445
*/
55-
protected function compileUniqueSqlServerIndexStatement($table, $column)
46+
protected function compileUniqueSqlServerIndexStatement(string $table, string $column): string
5647
{
5748
return sprintf('create unique index %s on %s (%s) where %s is not null',
5849
implode('_', [$table, $column, 'unique']),
@@ -61,4 +52,4 @@ protected function compileUniqueSqlServerIndexStatement($table, $column)
6152
$column
6253
);
6354
}
64-
}
55+
};

src/LdapAuthServiceProvider.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ protected function registerMigrations(): void
4343
return;
4444
}
4545

46-
if (! class_exists('AddLdapColumnsToUsersTable')) {
47-
$this->publishes([
48-
__DIR__.'/../database/migrations/add_ldap_columns_to_users_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_add_ldap_columns_to_users_table.php'),
49-
], 'migrations');
50-
}
46+
$this->publishes([
47+
__DIR__.'/../database/migrations' => database_path('migrations'),
48+
], 'migrations');
5149
}
5250

5351
/**

tests/Feature/DatabaseTestCase.php

+11-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Auth\EloquentUserProvider;
66
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
78
use Illuminate\Support\Facades\Schema;
89
use LdapRecord\Laravel\Auth\DatabaseUserProvider;
910
use LdapRecord\Laravel\Import\UserSynchronizer;
@@ -13,33 +14,26 @@
1314
use LdapRecord\Models\ActiveDirectory\User;
1415
use LdapRecord\Models\Model;
1516
use Mockery as m;
17+
use Orchestra\Testbench\Attributes\WithMigration;
1618

19+
#[WithMigration]
1720
class DatabaseTestCase extends TestCase
1821
{
22+
use RefreshDatabase;
23+
1924
protected function setUp(): void
2025
{
2126
parent::setUp();
2227

23-
$this->createUsersTable();
28+
Schema::table('users', function (Blueprint $table) {
29+
$table->softDeletes();
30+
});
2431
}
2532

26-
protected function createUsersTable()
33+
protected function defineDatabaseMigrations()
2734
{
28-
// Setup the users database table.
29-
Schema::create('users', function (Blueprint $table) {
30-
$table->bigIncrements('id');
31-
$table->string('name');
32-
$table->string('email')->unique();
33-
$table->timestamp('email_verified_at')->nullable();
34-
$table->string('password');
35-
$table->rememberToken();
36-
$table->timestamps();
37-
$table->softDeletes();
38-
39-
// Additional fields for LdapRecord.
40-
$table->string('guid')->unique()->nullable();
41-
$table->string('domain')->nullable();
42-
});
35+
$this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
36+
$this->loadMigrationsFrom(__DIR__.'/../../vendor/laravel/sanctum/database/migrations');
4337
}
4438

4539
protected function getMockLdapModel(array $attributes = [])

tests/Feature/SanctumTest.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace LdapRecord\Laravel\Tests\Feature;
44

5-
use Illuminate\Foundation\Testing\DatabaseMigrations;
65
use Illuminate\Http\Request;
76
use Illuminate\Support\Facades\Auth;
87
use Illuminate\Support\Facades\Route;
@@ -14,7 +13,6 @@
1413
class SanctumTest extends DatabaseTestCase
1514
{
1615
use CreatesTestUsers;
17-
use DatabaseMigrations;
1816

1917
protected function setUp(): void
2018
{
@@ -36,10 +34,16 @@ protected function setUp(): void
3634

3735
Route::post('api/sanctum/token', function (Request $request) {
3836
if (Auth::validate($request->only('mail', 'password'))) {
39-
return ['token' => Auth::getLastAttempted()->createToken($request->device_name)->plainTextToken];
37+
return [
38+
'token' => Auth::getLastAttempted()
39+
->createToken($request->device_name)
40+
->plainTextToken,
41+
];
4042
}
4143

42-
throw ValidationException::withMessages(['email' => 'The provided credentials are incorrect.']);
44+
throw ValidationException::withMessages([
45+
'email' => 'The provided credentials are incorrect.',
46+
]);
4347
});
4448
}
4549

tests/Unit/LdapAuthServiceProviderTest.php

-22
This file was deleted.

0 commit comments

Comments
 (0)