A testbench, BF tests

This commit is contained in:
a6a2f5842 2025-12-03 14:18:38 +01:00
parent 1762db82cd
commit 2bdc871640
16 changed files with 252 additions and 1 deletions

View File

@ -34,5 +34,9 @@ jobs:
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-update --no-interaction
composer update --prefer-dist --no-interaction --no-progress
- name: Setup testbench
run: |
composer run-script post-autoload-dump
- name: Execute tests
run: vendor/bin/phpunit --testdox

1
.gitignore vendored
View File

@ -3,7 +3,6 @@ sandbox
vendor
composer.lock
.idea/
workbench
.phpunit.result.cache
.phpunit.cache
.env

View File

View File

@ -0,0 +1,47 @@
<?php
namespace Workbench\App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Blax\Shop\Traits\HasShoppingCapabilities;
use Blax\Shop\Traits\HasStripeAccount;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable, HasShoppingCapabilities, HasUuids, HasStripeAccount;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace Workbench\App\Providers;
use Illuminate\Support\ServiceProvider;
class WorkbenchServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}

View File

@ -0,0 +1,19 @@
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use function Orchestra\Testbench\default_skeleton_path;
return Application::configure(basePath: $APP_BASE_PATH ?? default_skeleton_path())
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();

View File

@ -0,0 +1,5 @@
<?php
return [
//
];

View File

View File

@ -0,0 +1,54 @@
<?php
namespace Workbench\Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Workbench\App\Models\User;
/**
* @template TModel of \Workbench\App\Models\User
*
* @extends \Illuminate\Database\Eloquent\Factories\Factory<TModel>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* The name of the factory's corresponding model.
*
* @var class-string<TModel>
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}

View File

View File

@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
};

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration');
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};

View File

@ -0,0 +1,23 @@
<?php
namespace Workbench\Database\Seeders;
use Illuminate\Database\Seeder;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Workbench\Database\Factories\UserFactory;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// UserFactory::new()->times(10)->create();
UserFactory::new()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
}

View File

View File

@ -0,0 +1,8 @@
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
// Artisan::command('inspire', function () {
// $this->comment(Inspiring::quote());
// })->purpose('Display an inspiring quote');

7
workbench/routes/web.php Normal file
View File

@ -0,0 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});