Skip to content

Commit 27da53d

Browse files
committed
tests: configure testbench
1 parent 49314dd commit 27da53d

File tree

7 files changed

+121
-2
lines changed

7 files changed

+121
-2
lines changed

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"psr-4": {
2727
"CalebDW\\SqlEntities\\Tests\\": "tests/",
2828
"Workbench\\App\\": "workbench/app/",
29-
"Workbench\\Database\\Entities\\": "workbench/database/entities/"
29+
"Workbench\\Database\\Entities\\": "workbench/database/entities/",
30+
"Workbench\\Database\\Factories\\": "workbench/database/factories/"
3031
}
3132
},
3233
"require": {
@@ -71,7 +72,11 @@
7172
"post-autoload-dump": [
7273
"@prepare"
7374
],
74-
"prepare": "@php vendor/bin/testbench package:discover --ansi"
75+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
76+
"lint": [
77+
"@php vendor/bin/pint --ansi",
78+
"@php vendor/bin/phpstan analyse --verbose --ansi"
79+
]
7580
},
7681
"prefer-stable": true,
7782
"minimum-stability": "dev"

workbench/app/Models/.gitkeep

Whitespace-only changes.

workbench/app/Models/User.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Workbench\App\Models;
4+
5+
// use Illuminate\Contracts\Auth\MustVerifyEmail;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Foundation\Auth\User as Authenticatable;
8+
use Illuminate\Notifications\Notifiable;
9+
10+
class User extends Authenticatable
11+
{
12+
/** @use HasFactory<\Workbench\Database\Factories\UserFactory> */
13+
use HasFactory, Notifiable;
14+
15+
/**
16+
* The attributes that are mass assignable.
17+
*
18+
* @var list<string>
19+
*/
20+
protected $fillable = [
21+
'name',
22+
'email',
23+
'password',
24+
];
25+
26+
/**
27+
* The attributes that should be hidden for serialization.
28+
*
29+
* @var list<string>
30+
*/
31+
protected $hidden = [
32+
'password',
33+
'remember_token',
34+
];
35+
36+
/**
37+
* Get the attributes that should be cast.
38+
*
39+
* @return array<string, string>
40+
*/
41+
protected function casts(): array
42+
{
43+
return [
44+
'email_verified_at' => 'datetime',
45+
'password' => 'hashed',
46+
];
47+
}
48+
}

workbench/bootstrap/app.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Foundation\Application;
6+
use Illuminate\Foundation\Configuration\Exceptions;
7+
8+
use function Orchestra\Testbench\default_skeleton_path;
9+
10+
return Application::configure(basePath: $APP_BASE_PATH ?? default_skeleton_path())
11+
->withExceptions(function (Exceptions $exceptions) {
12+
})->create();

workbench/database/factories/.gitkeep

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Workbench\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Str;
8+
use Workbench\App\Models\User;
9+
10+
/**
11+
* @template TModel of \Workbench\App\Models\User
12+
*
13+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<TModel>
14+
*/
15+
class UserFactory extends Factory
16+
{
17+
/**
18+
* The current password being used by the factory.
19+
*/
20+
protected static ?string $password;
21+
22+
/**
23+
* The name of the factory's corresponding model.
24+
*
25+
* @var class-string<TModel>
26+
*/
27+
protected $model = User::class;
28+
29+
/**
30+
* Define the model's default state.
31+
*
32+
* @return array<string, mixed>
33+
*/
34+
public function definition(): array
35+
{
36+
return [
37+
'name' => fake()->name(),
38+
'email' => fake()->unique()->safeEmail(),
39+
'email_verified_at' => now(),
40+
'password' => static::$password ??= Hash::make('password'),
41+
'remember_token' => Str::random(10),
42+
];
43+
}
44+
45+
/**
46+
* Indicate that the model's email address should be unverified.
47+
*/
48+
public function unverified(): static
49+
{
50+
return $this->state(fn (array $attributes) => [
51+
'email_verified_at' => null,
52+
]);
53+
}
54+
}

workbench/database/migrations/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)