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]>
58 lines
2.6 KiB
PHP
58 lines
2.6 KiB
PHP
<?php
|
|
|
|
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
|
use App\Modules\Customers\Domain\Contracts\CustomerRepository;
|
|
use App\Modules\Customers\Domain\Entities\Customer;
|
|
use App\Modules\Customers\Domain\Enums\CustomerType;
|
|
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
|
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
|
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('stores a new customer and reads it back as an entity', function () {
|
|
$repository = app(CustomerRepository::class);
|
|
|
|
$saved = $repository->save(Customer::register(new CustomerName('Mainos Oy'), CustomerType::Company, new BusinessId('0737546-2')));
|
|
$found = $repository->findById((int) $saved->id());
|
|
|
|
expect($saved->id())->toBeInt()
|
|
->and($found?->name()->value)->toBe('Mainos Oy')
|
|
->and($found?->type())->toBe(CustomerType::Company)
|
|
->and($found?->businessId()?->value)->toBe('0737546-2');
|
|
});
|
|
|
|
it('updates a stored customer', function () {
|
|
$repository = app(CustomerRepository::class);
|
|
$customer = $repository->save(Customer::register(new CustomerName('Mainos Oy'), CustomerType::Company));
|
|
|
|
$customer->changeDetails(new CustomerName('Maija Meikäläinen'), CustomerType::Consumer, null);
|
|
$repository->save($customer);
|
|
|
|
expect(CustomerModel::query()->count())->toBe(1)
|
|
->and(CustomerModel::query()->sole()->type)->toBe(CustomerType::Consumer);
|
|
});
|
|
|
|
it('tells whether another customer has the business id', function () {
|
|
$repository = app(CustomerRepository::class);
|
|
$customer = CustomerModel::factory()->company('0737546-2')->create();
|
|
|
|
expect($repository->isBusinessIdTaken(new BusinessId('0737546-2')))->toBeTrue()
|
|
->and($repository->isBusinessIdTaken(new BusinessId('0737546-2'), $customer->id))->toBeFalse()
|
|
->and($repository->isBusinessIdTaken(new BusinessId('1572860-0')))->toBeFalse();
|
|
});
|
|
|
|
it('returns summaries filtered by name or business id, ordered by name', function () {
|
|
CustomerModel::factory()->create(['name' => 'Bravo Media Oy']);
|
|
CustomerModel::factory()->company('0737546-2')->create(['name' => 'Alfa Media Oy']);
|
|
CustomerModel::factory()->create(['name' => 'Kahvila Kulma']);
|
|
|
|
$queries = app(CustomerQueries::class);
|
|
|
|
expect(array_map(fn ($summary) => $summary->name, $queries->search('media')))->toBe(['Alfa Media Oy', 'Bravo Media Oy'])
|
|
->and($queries->paginate('0737546')->total())->toBe(1)
|
|
->and($queries->paginate(null)->total())->toBe(3)
|
|
->and($queries->search('100%'))->toBe([]);
|
|
});
|