Introduce a modular monolith under app/Modules with Domain, Application, Infrastructure and Presentation layers. - Shared module: DomainException base, TransactionManager and an EventDispatcher that publishes events after commit. - Customers module: Customer entity, CustomerName and BusinessId (Y-tunnus checksum) value objects, RegisterCustomer/UpdateCustomer use cases, CustomerQueries read contract, Eloquent repository, and Livewire list and form pages with Finnish translations. - Pest arch tests enforce layer and module dependency rules for every module; Larastan (level 6) added as a dev dependency. - Raise Flux error text contrast to meet WCAG 2.2 AA. - Document the architecture in docs/architecture.md and CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
56 lines
2.0 KiB
PHP
56 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Modules\Customers\Application\DTOs\CustomerDetailsData;
|
|
use App\Modules\Customers\Application\UseCases\RegisterCustomer;
|
|
use App\Modules\Customers\Domain\Enums\CustomerType;
|
|
use App\Modules\Customers\Domain\Events\CustomerRegistered;
|
|
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
|
use App\Modules\Shared\Application\Contracts\EventDispatcher;
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('rolls back everything when the work fails', function () {
|
|
expect(fn () => app(TransactionManager::class)->run(function (): void {
|
|
CustomerModel::factory()->create();
|
|
|
|
throw new RuntimeException('fail');
|
|
}))->toThrow(RuntimeException::class);
|
|
|
|
expect(CustomerModel::query()->count())->toBe(0);
|
|
});
|
|
|
|
it('publishes events only after the transaction commits', function () {
|
|
Event::fake([CustomerRegistered::class]);
|
|
|
|
app(TransactionManager::class)->run(function (): void {
|
|
app(EventDispatcher::class)->dispatch(new CustomerRegistered(1));
|
|
|
|
Event::assertNotDispatched(CustomerRegistered::class);
|
|
});
|
|
|
|
Event::assertDispatched(CustomerRegistered::class);
|
|
});
|
|
|
|
it('drops events of a rolled back transaction', function () {
|
|
Event::fake([CustomerRegistered::class]);
|
|
|
|
rescue(fn () => app(TransactionManager::class)->run(function (): void {
|
|
app(EventDispatcher::class)->dispatch(new CustomerRegistered(1));
|
|
|
|
throw new RuntimeException('fail');
|
|
}), report: false);
|
|
|
|
Event::assertNotDispatched(CustomerRegistered::class);
|
|
});
|
|
|
|
it('announces a registered customer to listeners', function () {
|
|
Event::fake([CustomerRegistered::class]);
|
|
|
|
$customerId = app(RegisterCustomer::class)->execute(new CustomerDetailsData('Mainos Oy', CustomerType::Company));
|
|
|
|
Event::assertDispatched(CustomerRegistered::class, fn (CustomerRegistered $event) => $event->customerId === $customerId);
|
|
});
|