|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Relaticle\Flowforge\Tests; |
| 6 | + |
| 7 | +use BladeUI\Heroicons\BladeHeroiconsServiceProvider; |
| 8 | +use BladeUI\Icons\BladeIconsServiceProvider; |
| 9 | +use Filament\Actions\ActionsServiceProvider; |
| 10 | +use Filament\FilamentManager; |
| 11 | +use Filament\Forms\FormsServiceProvider; |
| 12 | +use Filament\Infolists\InfolistsServiceProvider; |
| 13 | +use Filament\Notifications\NotificationsServiceProvider; |
| 14 | +use Filament\Support\SupportServiceProvider; |
| 15 | +use Filament\Tables\TablesServiceProvider; |
| 16 | +use Illuminate\Database\Eloquent\Factories\Factory; |
| 17 | +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; |
| 18 | +use Livewire\LivewireServiceProvider; |
| 19 | +use Orchestra\Testbench\Concerns\WithWorkbench; |
| 20 | +use Orchestra\Testbench\TestCase as Orchestra; |
| 21 | +use Relaticle\Flowforge\FlowforgeServiceProvider; |
| 22 | +use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider; |
| 23 | + |
| 24 | +/** |
| 25 | + * Test case for standalone Livewire usage WITHOUT the Filament Panel Builder. |
| 26 | + * |
| 27 | + * Excludes FilamentServiceProvider and TestPanelProvider to verify the package |
| 28 | + * works without a panel registered. |
| 29 | + * |
| 30 | + * Note: In a real standalone install (without filament/filament), the Filament |
| 31 | + * facade class won't exist and class_exists() guards in filament/tables skip |
| 32 | + * panel-dependent calls entirely. In our test environment, filament/filament IS |
| 33 | + * installed as a dev dependency, so we register a minimal FilamentManager binding |
| 34 | + * to satisfy those guards without configuring any panel. |
| 35 | + */ |
| 36 | +class StandaloneTestCase extends Orchestra |
| 37 | +{ |
| 38 | + use LazilyRefreshDatabase; |
| 39 | + use WithWorkbench; |
| 40 | + |
| 41 | + protected function setUp(): void |
| 42 | + { |
| 43 | + parent::setUp(); |
| 44 | + |
| 45 | + Factory::guessFactoryNamesUsing( |
| 46 | + fn (string $modelName) => 'Relaticle\\Flowforge\\Database\\Factories\\' . class_basename($modelName) . 'Factory' |
| 47 | + ); |
| 48 | + |
| 49 | + // Register minimal FilamentManager binding. This is only needed because |
| 50 | + // filament/filament is a dev dependency (for panel tests), making the |
| 51 | + // Filament facade class available. The tables package's HasFilters trait |
| 52 | + // uses class_exists(Filament::class) to guard tenant-aware session keys, |
| 53 | + // which passes in our test env but would be false in a real standalone install. |
| 54 | + if (! $this->app->bound('filament')) { |
| 55 | + $this->app->scoped('filament', fn () => new FilamentManager); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + protected function getPackageProviders($app): array |
| 60 | + { |
| 61 | + $providers = [ |
| 62 | + ActionsServiceProvider::class, |
| 63 | + BladeCaptureDirectiveServiceProvider::class, |
| 64 | + BladeHeroiconsServiceProvider::class, |
| 65 | + BladeIconsServiceProvider::class, |
| 66 | + FormsServiceProvider::class, |
| 67 | + InfolistsServiceProvider::class, |
| 68 | + LivewireServiceProvider::class, |
| 69 | + NotificationsServiceProvider::class, |
| 70 | + SupportServiceProvider::class, |
| 71 | + TablesServiceProvider::class, |
| 72 | + FlowforgeServiceProvider::class, |
| 73 | + ]; |
| 74 | + |
| 75 | + sort($providers); |
| 76 | + |
| 77 | + return $providers; |
| 78 | + } |
| 79 | + |
| 80 | + protected function defineEnvironment($app): void |
| 81 | + { |
| 82 | + config()->set('database.default', 'testing'); |
| 83 | + config()->set('database.connections.testing', [ |
| 84 | + 'driver' => 'sqlite', |
| 85 | + 'database' => ':memory:', |
| 86 | + 'prefix' => '', |
| 87 | + ]); |
| 88 | + |
| 89 | + config()->set('app.key', 'base64:' . base64_encode(random_bytes(32))); |
| 90 | + config()->set('session.driver', 'array'); |
| 91 | + config()->set('session.encrypt', false); |
| 92 | + |
| 93 | + config()->set('view.paths', [ |
| 94 | + resource_path('views'), |
| 95 | + __DIR__ . '/../resources/views', |
| 96 | + ]); |
| 97 | + } |
| 98 | + |
| 99 | + protected function defineDatabaseMigrations(): void |
| 100 | + { |
| 101 | + $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); |
| 102 | + } |
| 103 | +} |
0 commit comments