Skip to content

Commit 31e9f63

Browse files
specialtacticsMax Snow
andauthored
Laravel 12 support & Testing improvements (#81)
* Package updates, testing updates * Test laravel 12 in ci * Update readme --------- Co-authored-by: Max Snow <[email protected]>
1 parent c1e3041 commit 31e9f63

File tree

15 files changed

+144
-41
lines changed

15 files changed

+144
-41
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
matrix:
1717
stability: [prefer-stable]
1818
php: [8.2, 8.3, 8.4]
19-
laravel: [11]
19+
laravel: [12]
2020

2121
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
2222

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
],
1212
"require": {
1313
"php": "^8.2",
14-
"api-ecosystem-for-laravel/dingo-api": "^4.4.1",
15-
"php-open-source-saver/jwt-auth": "^2.7",
16-
"illuminate/support": "^11.0",
14+
"api-ecosystem-for-laravel/dingo-api": "^4.6",
15+
"php-open-source-saver/jwt-auth": "^2.8",
16+
"illuminate/support": "^12.0",
1717
"ramsey/uuid": "^4.7",
18-
"nesbot/carbon": "^2.0|^3.0"
18+
"nesbot/carbon": "^3.0"
1919
},
2020
"require-dev": {
2121
"ext-json": "*",
22-
"beyondcode/laravel-dump-server": "^2.0",
23-
"fakerphp/faker": "^1.23",
22+
"beyondcode/laravel-dump-server": "^2.1",
23+
"fakerphp/faker": "^1.24",
2424
"mockery/mockery": "^1.6",
2525
"nunomaduro/collision": "^8.6",
2626
"phpunit/phpunit": "^11.5",
27-
"orchestra/testbench": "^9.9"
27+
"orchestra/testbench": "^10.3"
2828
},
2929
"autoload": {
3030
"psr-4": {
@@ -37,9 +37,10 @@
3737
"Specialtactics\\L5Api\\Tests\\": "test/tests/",
3838
"Specialtactics\\L5Api\\Test\\Mocks\\": "test/mocks/",
3939
"App\\": "test/app/",
40-
"Database\\": "test/database/"
40+
"Database\\Factories\\": "test/database/factories/",
41+
"Database\\Seeders\\": "test/database/seeders/"
4142
},
42-
"classmap": ["test/database/seeds/"]
43+
"classmap": ["test/database/migrations/"]
4344
},
4445
"extra": {
4546
"laravel": {

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Please go to [The boilerplate wiki](https://github.com/specialtactics/laravel-ap
1212

1313
| Laravel Version | Boilerplate Version | Minimum PHP Version | Support Status |
1414
|-----------------|---------------------|---------------------|----------------|
15+
| 12.x | 7.x.x | 8.2 | Supported |
1516
| 11.x | 6.x.x | 8.2 | Supported |
16-
| 10.x | 5.x.x | 8.1 | Supported |
17+
| 10.x | 5.x.x | 8.1 | Not Supported |
1718
| 9.x | 4.x.x | 8.0 | Not Supported |
1819
| 8.x | 3.x.x | 7.3 | Not Supported |
1920
| 7.x | 2.x.x | 7.2.5 | Not Supported |

test/app/Models/User.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
1313
use Illuminate\Support\Str;
1414
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
15-
use \Illuminate\Support\Facades\Hash;
1615
use App\Models\Role;
1716
use Database\Factories\UserFactory;
1817

@@ -43,29 +42,35 @@ class User extends BaseModel implements
4342
'name', 'email', 'password', 'primary_role'
4443
];
4544

46-
protected $casts = [
47-
'verifiable_until' => 'datetime',
48-
'password' => 'hashed',
49-
];
50-
5145
/**
5246
* The attributes that should be hidden for arrays and API output
5347
*/
5448
protected $hidden = [
5549
'password', 'remember_token', 'primary_role',
5650
];
5751

52+
/**
53+
* Get the attributes that should be cast.
54+
*
55+
* @return array<string, string>
56+
*/
57+
protected function casts(): array
58+
{
59+
return [
60+
'email_verified_at' => 'datetime',
61+
'password' => 'hashed',
62+
];
63+
}
64+
5865
/**
5966
* Model's boot function
6067
*/
6168
public static function boot(): void
6269
{
6370
parent::boot();
6471

65-
static::creating(function (User $user) {
66-
if (is_null($user->password)) {
67-
$user->password = Hash::make(Str::random(64));
68-
}
72+
static::saving(function (User $user) {
73+
$user->email = Str::lower($user->email);
6974
});
7075
}
7176

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Database\Factories;
6+
7+
use App\Models\Role;
8+
use App\Models\User;
9+
use Illuminate\Database\Eloquent\Factories\Factory;
10+
use Illuminate\Support\Collection;
11+
use Illuminate\Support\Str;
12+
13+
/**
14+
* @extends Factory<User>
15+
*/
16+
class UserFactory extends Factory
17+
{
18+
public const DEFAULT_PASSWORD = 'secret';
19+
20+
/**
21+
* The name of the factory's corresponding model.
22+
*
23+
* @var string
24+
*/
25+
protected $model = User::class;
26+
27+
protected static ?Collection $allRoles = null;
28+
29+
/**
30+
* Retrieve all roles
31+
*/
32+
public static function getAllRoles(): Collection
33+
{
34+
if (is_null(static::$allRoles)) {
35+
static::$allRoles = Role::all();
36+
}
37+
38+
return static::$allRoles;
39+
}
40+
41+
/**
42+
* Define the model's default state.
43+
*/
44+
public function definition(): array
45+
{
46+
return [
47+
'name' => $this->faker->name(),
48+
'email' => microtime(true) . '_' . $this->faker->unique()->safeEmail(),
49+
'email_verified_at' => now(),
50+
'password' => static::DEFAULT_PASSWORD,
51+
'remember_token' => Str::random(10),
52+
'active' => true,
53+
];
54+
}
55+
56+
public function adminRole(): UserFactory
57+
{
58+
return $this->state(function (array $attributes): array {
59+
return [
60+
'primary_role' => static::getAllRoles()
61+
->firstWhere('name', '=', Role::ROLE_ADMIN)
62+
->getKey(),
63+
];
64+
});
65+
}
66+
67+
/**
68+
* Indicate that the model's email address should be unverified.
69+
*/
70+
public function unverified(): UserFactory
71+
{
72+
return $this->state(function (array $attributes): array {
73+
return [
74+
'email_verified_at' => null,
75+
];
76+
});
77+
}
78+
}

test/database/migrations/2018_04_30_000010_create_test_users_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public function up()
2121
$table->string('name');
2222
$table->string('email')->unique();
2323
$table->string('password');
24+
$table->boolean('active')->default(true);
2425

2526
$table->uuid('primary_role')->nullable();
2627
$table->foreign('primary_role')->references('role_id')->on('roles')->onDelete('set null');
28+
$table->timestamp('email_verified_at')->nullable();
2729

2830
$table->primary('user_id');
2931

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
46

57
class BaseSeeder extends Seeder {
@@ -9,23 +11,23 @@ class BaseSeeder extends Seeder {
911
public $faker = null;
1012

1113
/**
12-
* Run the database seeds.
14+
* Run the database Seeders.
1315
*
1416
* @return void
1517
*/
1618
public function run()
1719
{
1820
// You can set the locale of your seeder as a parameter to the create function
1921
// Available locales: https://github.com/fzaninotto/Faker/tree/master/src/Faker/Provider
20-
$this->faker = Faker\Factory::create();
22+
$this->faker = \Faker\Factory::create();
2123

2224
$this->before();
2325

2426
// Run in any environment
2527
$this->runAlways();
2628

2729
// Production Only
28-
if (App::environment() == 'production') {
30+
if (app()->environment() === 'production') {
2931
$this->runProduction();
3032
}
3133
// Fake environments
@@ -37,23 +39,23 @@ public function run()
3739
}
3840

3941
/**
40-
* Run fake seeds - for non production environments
42+
* Run fake Seeders - for non production environments
4143
*
4244
* @return void
4345
*/
4446
public function runFake() {
4547
}
4648

4749
/**
48-
* Run seeds to be ran only on production environments
50+
* Run Seeders to be ran only on production environments
4951
*
5052
* @return void
5153
*/
5254
public function runProduction() {
5355
}
5456

5557
/**
56-
* Run seeds to be ran on every environment (including production)
58+
* Run Seeders to be ran on every environment (including production)
5759
*
5860
* @return void
5961
*/
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
46

57
class DatabaseSeeder extends Seeder
68
{
79
/**
8-
* Run the database seeds.
10+
* Run the database Seeders.
911
*
1012
* @return void
1113
*/
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use App\Models\Forum;
46

57
class ForumsSeeder extends BaseSeeder
68
{
79
/**
8-
* Run fake seeds - for non production environments
10+
* Run fake Seeders - for non production environments
911
*
1012
* @return mixed
1113
*/
@@ -16,7 +18,7 @@ public function runFake() {
1618
}
1719

1820
/**
19-
* Run seeds to be ran only on production environments
21+
* Run Seeders to be ran only on production environments
2022
*
2123
* @return mixed
2224
*/
@@ -25,7 +27,7 @@ public function runProduction() {
2527
}
2628

2729
/**
28-
* Run seeds to be ran on every environment (including production)
30+
* Run Seeders to be ran on every environment (including production)
2931
*
3032
* @return mixed
3133
*/
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use App\Models\Forum;
46
use App\Models\Topic;
57
use App\Models\Post;
68

79
class PostsSeeder extends BaseSeeder
810
{
911
/**
10-
* Run fake seeds - for non production environments
12+
* Run fake Seeders - for non production environments
1113
*
1214
* @return mixed
1315
*/
@@ -26,7 +28,7 @@ public function runFake() {
2628
}
2729

2830
/**
29-
* Run seeds to be ran only on production environments
31+
* Run Seeders to be ran only on production environments
3032
*
3133
* @return mixed
3234
*/
@@ -35,7 +37,7 @@ public function runProduction() {
3537
}
3638

3739
/**
38-
* Run seeds to be ran on every environment (including production)
40+
* Run Seeders to be ran on every environment (including production)
3941
*
4042
* @return mixed
4143
*/

0 commit comments

Comments
 (0)