Skip to content

Commit

Permalink
Setup Workbench and Fix Test
Browse files Browse the repository at this point in the history
  • Loading branch information
nasrulhazim committed Nov 27, 2024
1 parent c6ccb45 commit 67580b5
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 15 deletions.
48 changes: 34 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@
}
],
"require": {
"php": "^8.1 | ^8.2 | ^8.3",
"php": "^8.2 | ^8.3",
"cleaniquecoders/traitify": "^1.0",
"illuminate/contracts": "^9.0 | ^10.0 | ^11.0",
"illuminate/contracts": "^10.0 | ^11.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.1|^7.9",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^1.21|^2.0",
"pestphp/pest-plugin-laravel": "^1.4|^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0"
"laravel/pint": "^1.14",
"nunomaduro/collision": "^8.1.1||^7.10.0",
"orchestra/testbench": "^9.5",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-arch": "^2.7",
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3"
},
"autoload": {
"psr-4": {
Expand All @@ -40,15 +41,34 @@
},
"autoload-dev": {
"psr-4": {
"CleaniqueCoders\\MailHistory\\Tests\\": "tests/"
"CleaniqueCoders\\MailHistory\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"post-autoload-dump": [
"@clear",
"@prepare",
"@php ./vendor/bin/testbench package:discover --ansi"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
"format": "vendor/bin/pint",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/pint --ansi",
"@php vendor/bin/phpstan analyse --verbose --ansi"
]
},
"config": {
"sort-packages": true,
Expand All @@ -69,4 +89,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
15 changes: 14 additions & 1 deletion tests/MailHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@
use Illuminate\Mail\Events\MessageSent;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\DB;

beforeEach(function () {
// Set view paths
config()->set('view.paths', [
dirname(__FILE__).'/resources/views',
]);

// Commit any existing transactions
try {
DB::commit();
} catch (\Exception $e) {
// Ignore any commit errors since there might not be an active transaction
}

// Run migrations
Artisan::call('vendor:publish', [
'--tag' => 'mailhistory-migrations',
'--force' => true,
]);

// Fresh migration without transaction wrapping
DB::unprepared('PRAGMA foreign_keys = OFF;');
Artisan::call('migrate:fresh');
DB::unprepared('PRAGMA foreign_keys = ON;');
});

it('has MessageSending and MessageSent event listened to if the package is enabled', function () {
Expand All @@ -28,7 +42,6 @@
});

it('does not has the MessageSending and MessageSent event listened to if the package is disabled', function () {

config([
'mailhistory.enabled' => false,
]);
Expand Down
Empty file added workbench/app/Models/.gitkeep
Empty file.
45 changes: 45 additions & 0 deletions workbench/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Workbench\App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
use HasFactory, Notifiable;

/**
* 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',
];
}
24 changes: 24 additions & 0 deletions workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -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
{
//
}
}
19 changes: 19 additions & 0 deletions workbench/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -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();
Empty file.
54 changes: 54 additions & 0 deletions workbench/database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -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,
]);
}
}
Empty file.
23 changes: 23 additions & 0 deletions workbench/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -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(10)->create();

UserFactory::new()->create([
'name' => 'Test User',
'email' => '[email protected]',
]);
}
}
Empty file.
8 changes: 8 additions & 0 deletions workbench/routes/console.php
Original file line number Diff line number Diff line change
@@ -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')->hourly();
7 changes: 7 additions & 0 deletions workbench/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});

0 comments on commit 67580b5

Please sign in to comment.