|  | 
| 1 | 1 | <?php | 
| 2 | 2 | 
 | 
|  | 3 | +declare(strict_types=1); | 
|  | 4 | + | 
| 3 | 5 | use Kirschbaum\Loop\Facades\Loop as LoopFacade; | 
| 4 | 6 | use Kirschbaum\Loop\Loop; | 
|  | 7 | +use Kirschbaum\Loop\LoopTools; | 
| 5 | 8 | use Kirschbaum\Loop\Toolkits\LaravelModelToolkit; | 
| 6 | 9 | use Workbench\App\Models\User; | 
| 7 | 10 | 
 | 
| 8 | 11 | beforeEach(function () { | 
|  | 12 | +    // Simulate Octane worker reset by clearing resolved instances and stored tools | 
| 9 | 13 |     app()->forgetInstance(Loop::class); | 
| 10 |  | -    app()->forgetInstance('loop.registrations'); | 
|  | 14 | + | 
|  | 15 | +    if (app()->bound(LoopTools::class)) { | 
|  | 16 | +        app(LoopTools::class)->clear(); | 
|  | 17 | +    } | 
| 11 | 18 | }); | 
| 12 | 19 | 
 | 
| 13 | 20 | test('toolkits persist after instance recreation', function () { | 
|  | 
| 17 | 24 |     $firstTools = $firstInstance->getPrismTools(); | 
| 18 | 25 | 
 | 
| 19 | 26 |     expect($firstTools->count()) | 
| 20 |  | -        ->toBeGreaterThan(0, 'First instance should have tools from registered toolkit'); | 
|  | 27 | +        ->toBeGreaterThan(0); | 
| 21 | 28 | 
 | 
| 22 |  | -    app()->forgetInstance(Loop::class); // Simulates Octane instance recreation. | 
|  | 29 | +    app()->forgetInstance(Loop::class); // Simulate Octane instance recreation. | 
| 23 | 30 | 
 | 
| 24 | 31 |     $secondInstance = app(Loop::class); | 
| 25 | 32 |     $secondTools = $secondInstance->getPrismTools(); | 
| 26 | 33 | 
 | 
| 27 | 34 |     expect($secondTools->count()) | 
| 28 |  | -        ->toBeGreaterThan(0, 'Second instance should have restored tools from registrations') | 
| 29 |  | -        ->and($secondTools->count()) | 
| 30 |  | -        ->toEqual($firstTools->count(), 'Both instances should have the same number of tools'); | 
|  | 35 | +        ->toEqual($firstTools->count()); | 
| 31 | 36 | }); | 
| 32 | 37 | 
 | 
| 33 | 38 | test('multiple toolkit registrations are preserved', function () { | 
| 34 | 39 |     LoopFacade::toolkit(LaravelModelToolkit::make([User::class])); | 
| 35 | 40 |     LoopFacade::toolkit(LaravelModelToolkit::make([User::class])); | 
| 36 | 41 | 
 | 
| 37 | 42 |     $firstInstance = app(Loop::class); | 
| 38 |  | -    $firstTools = $firstInstance->getPrismTools(); | 
| 39 |  | -    $firstCount = $firstTools->count(); | 
|  | 43 | +    $firstCount = $firstInstance->getPrismTools()->count(); | 
| 40 | 44 | 
 | 
| 41 |  | -    expect($firstCount)->toBeGreaterThan(0, 'Should have tools from multiple registrations'); | 
|  | 45 | +    expect($firstCount) | 
|  | 46 | +        ->toBeGreaterThan(0); | 
| 42 | 47 | 
 | 
| 43 | 48 |     app()->forgetInstance(Loop::class); | 
| 44 | 49 | 
 | 
| 45 | 50 |     $secondInstance = app(Loop::class); | 
| 46 |  | -    $secondTools = $secondInstance->getPrismTools(); | 
|  | 51 | +    $secondCount = $secondInstance->getPrismTools()->count(); | 
| 47 | 52 | 
 | 
| 48 |  | -    expect($secondTools->count())->toEqual($firstCount, 'All toolkit registrations should be preserved'); | 
|  | 53 | +    expect($secondCount) | 
|  | 54 | +        ->toEqual($firstCount); | 
| 49 | 55 | }); | 
| 50 | 56 | 
 | 
| 51 | 57 | test('empty registrations handle gracefully', function () { | 
| 52 | 58 |     $instance = app(Loop::class); | 
| 53 | 59 |     $tools = $instance->getPrismTools(); | 
| 54 | 60 | 
 | 
| 55 |  | -    expect($tools->count())->toEqual(0, 'Should have no tools when nothing is registered'); | 
| 56 |  | -}); | 
| 57 |  | - | 
| 58 |  | -test('registrations are stored correctly', function () { | 
| 59 |  | -    LoopFacade::toolkit(LaravelModelToolkit::make([User::class])); | 
| 60 |  | - | 
| 61 |  | -    expect(app()->bound('loop.registrations'))->toBeTrue('Registrations should be stored in container'); | 
| 62 |  | - | 
| 63 |  | -    $registrations = app('loop.registrations'); | 
| 64 |  | -    expect($registrations) | 
| 65 |  | -        ->toBeArray('Registrations should be an array') | 
| 66 |  | -        ->and(count($registrations)) | 
| 67 |  | -        ->toBeGreaterThan(0, 'Should have at least one registration'); | 
| 68 |  | - | 
| 69 |  | -    foreach ($registrations as $registration) { | 
| 70 |  | -        expect(is_callable($registration))->toBeTrue('Each registration should be callable'); | 
| 71 |  | -    } | 
|  | 61 | +    expect($tools) | 
|  | 62 | +        ->toHaveCount(0); | 
| 72 | 63 | }); | 
0 commit comments