U-A/U-B: Prozesskern mit Fachmodulen, versionierten Modellen, eingefrorenem Prozessplan, ProcessRunner (harte/weiche Abhängigkeiten), CasePricing, Loyalty nur im Tester
CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11: 11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002). Volle Suite vor U-B: 785/785. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
98df5e9e3b
commit
7e22e12cac
80 files changed
+4628
-445
No files matched your search
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\AcceptOffer;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\SendOffer;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\CasePricing;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Loyalty\LoyaltyDiscount;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Database\Seeders\SiteSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Package U-B / requirement K8: loyalty proves the extensibility – two new modules and an A1 variant at existing
|
||||
* extension points, the price lines only before the price is fixed, never usable for real cases, the other archetypes
|
||||
* untouched. The business rules (count, look-back, percentage, no combination with special offers) are test
|
||||
* assumptions, not released rules (decisions E5–E7).
|
||||
*/
|
||||
#[Group('module:guest.loyalty_status')]
|
||||
#[Group('module:pricing.loyalty_discount')]
|
||||
class LoyaltyArchitectureProofTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-23 18:00'));
|
||||
$this->seed([PropertySeeder::class, SiteSeeder::class]);
|
||||
$this->property = Property::sole();
|
||||
Storage::fake('local');
|
||||
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||||
config(['mail.default' => 'array']);
|
||||
Mail::swap(new MailManager($this->app));
|
||||
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org']);
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
|
||||
public function test_without_contributing_modules_the_case_price_is_exactly_the_calculator_price(): void
|
||||
{
|
||||
$booking = $this->request('neu@example.org');
|
||||
$stay = $this->stay();
|
||||
|
||||
$this->assertEquals(app(PriceCalculator::class)->calculate($this->property, $stay), app(CasePricing::class)->quote($booking, $stay));
|
||||
}
|
||||
|
||||
public function test_a_returning_guest_gets_the_discount_line_after_the_status_check_and_before_the_price_is_fixed(): void
|
||||
{
|
||||
$this->formerStay('stamm@example.org');
|
||||
$booking = $this->loyaltyCase($this->request('stamm@example.org'));
|
||||
|
||||
$quote = app(CasePricing::class)->quote($booking, $this->stay());
|
||||
$plain = app(PriceCalculator::class)->calculate($this->property, $this->stay());
|
||||
$discount = collect($quote->lines)->first(fn ($line): bool => $line->type === QuoteLineType::Discount);
|
||||
|
||||
$this->assertNotNull($discount, 'the discount reads the status of the check before it');
|
||||
$this->assertSame(-(int) round($plain->rent() * 5 / 100), $discount->amount);
|
||||
$this->assertStringContainsString('1 frühere Aufenthalte', $discount->label);
|
||||
|
||||
// The offer fixes the price: the line is in the frozen quote, and the binding case gets no contribution any more.
|
||||
app(SendOffer::class)->handle($booking->fresh());
|
||||
$booking->refresh();
|
||||
$this->assertSame($quote->total(), $booking->total);
|
||||
$this->assertContains('discount', array_column($booking->quote['lines'], 'type'));
|
||||
app(AcceptOffer::class)->handle($booking->fresh(), $booking->offer_version);
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
|
||||
$this->assertEquals($plain, app(CasePricing::class)->quote($booking->fresh(), $this->stay()), 'no contribution after binding (R5)');
|
||||
$this->assertSame('loyalty_status', collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'loyalty_status')?->key);
|
||||
}
|
||||
|
||||
public function test_a_new_guest_and_an_unknown_status_get_no_discount_and_the_offer_is_never_held_back(): void
|
||||
{
|
||||
$new = $this->loyaltyCase($this->request('neu@example.org'));
|
||||
$this->assertSame(app(PriceCalculator::class)->calculate($this->property, $this->stay())->total(), app(CasePricing::class)->quote($new, $this->stay())->total());
|
||||
|
||||
$unknown = $this->loyaltyCase($this->request('ohne@example.org', '2026-11-20', '2026-11-23'));
|
||||
$unknown->guest->forceFill(['email' => null])->saveQuietly();
|
||||
$activity = collect(CaseActivities::for($unknown->fresh()))->firstWhere('key', 'loyalty_status');
|
||||
$this->assertStringContainsString('nicht feststellbar', $activity->detail);
|
||||
}
|
||||
|
||||
public function test_the_discount_is_not_combined_with_a_special_offer_discount(): void
|
||||
{
|
||||
$this->formerStay('stamm@example.org');
|
||||
$booking = $this->loyaltyCase($this->request('stamm@example.org'));
|
||||
$quote = app(PriceCalculator::class)->calculate($this->property, $this->stay())
|
||||
->withLine(new QuoteLine(QuoteLineType::Discount, 'Sonderangebot', 1, -1000, -1000));
|
||||
|
||||
$this->assertSame([], app(LoyaltyDiscount::class)->priceLines(CaseContext::of($booking), $quote));
|
||||
}
|
||||
|
||||
public function test_loyalty_cannot_reach_a_real_case_and_leaves_the_other_models_unchanged(): void
|
||||
{
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$using = array_keys(array_filter($catalogue->models(), fn ($model): bool => collect($model->variants())->contains(fn ($variant): bool => in_array('pricing.loyalty_discount', $model->modules($variant->key), true))));
|
||||
|
||||
$this->assertSame(['a1.offer'], $using, 'only the A1 offer model has the variant');
|
||||
$this->assertSame([], $catalogue->problems());
|
||||
foreach ($catalogue->models() as $key => $model) {
|
||||
$this->assertNotContains('guest.loyalty_status', $model->modules('standard'), "{$key}: standard course unchanged");
|
||||
}
|
||||
$this->expectExceptionMessage('nur im Prozess-Tester');
|
||||
ProcessPlan::freeze($this->request('neu@example.org')->process(), ['model' => 'a1.offer', 'variant' => 'loyalty']);
|
||||
}
|
||||
|
||||
private function loyaltyCase(Booking $booking): Booking
|
||||
{
|
||||
$plan = ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer', 'variant' => 'loyalty'], sandbox: true);
|
||||
$booking->forceFill(['profile' => [...$booking->profile, 'plan' => $plan->toArray()]])->saveQuietly();
|
||||
|
||||
return $booking->fresh();
|
||||
}
|
||||
|
||||
private function formerStay(string $email): void
|
||||
{
|
||||
$guest = Guest::query()->create(['tenant_id' => $this->property->tenant_id, 'first_name' => 'Stamm', 'last_name' => 'Gast', 'email' => 'alt-'.$email]);
|
||||
Booking::factory()->for($this->property)->create(['guest_id' => $guest->id, 'status' => BookingStatus::Completed, 'arrival' => '2025-08-01', 'departure' => '2025-08-08']);
|
||||
$guest->forceFill(['email' => $email])->saveQuietly();
|
||||
}
|
||||
|
||||
private function request(string $email, string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking
|
||||
{
|
||||
return app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, 'street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
}
|
||||
|
||||
private function stay(): StayRequest
|
||||
{
|
||||
return new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\ContributeCaseFacts;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Models\Booking;
|
||||
use App\Models\DataRequest;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Intake\Hold;
|
||||
use App\Process\Modules\StepState;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessRunner;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Database\Seeders\SiteSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\Support\Process\A1WithAddressCheck;
|
||||
use Tests\Support\Process\AddressVerification;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* The process core with the real modules: the frozen plan of a new case, the course of K1 (missing address,
|
||||
* clarification hold, data request, expired hold, late answer, offer), an external address check that waits without
|
||||
* holding the offer back (K2), retired versions of finished cases (T3) and the catalogue's consistency.
|
||||
*/
|
||||
#[Group('runner')]
|
||||
class ProcessCoreTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-23 18:00'));
|
||||
$this->seed([PropertySeeder::class, SiteSeeder::class]);
|
||||
$this->property = Property::sole();
|
||||
Storage::fake('local');
|
||||
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||||
config(['mail.default' => 'array']);
|
||||
Mail::swap(new MailManager($this->app));
|
||||
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org',
|
||||
'process_defaults' => ['processing' => 'automatic', 'clarification_hold_auto_minutes' => 120, 'data_request_mode' => 'automatic']]);
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
|
||||
public function test_the_catalogue_is_consistent(): void
|
||||
{
|
||||
$this->assertSame([], app(ProcessCatalogue::class)->problems());
|
||||
}
|
||||
|
||||
public function test_a_new_case_freezes_its_plan(): void
|
||||
{
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
|
||||
$plan = $booking->fresh()->profile['plan'];
|
||||
$this->assertSame(['a1.offer', 1, 'standard', ProcessPlan::DERIVED], [$plan['model'], $plan['model_version'], $plan['variant'], $plan['source']]);
|
||||
$this->assertSame(2, $plan['modules']['offer.binding']);
|
||||
$this->assertSame('Verbindliches Angebot', $plan['labels']['offer.binding']);
|
||||
$this->assertArrayNotHasKey('guest.loyalty_status', $plan['modules'], 'tester-only modules never enter a real plan');
|
||||
}
|
||||
|
||||
public function test_clarification_hold_runs_on_while_the_data_request_waits_and_the_late_answer_brings_the_offer(): void
|
||||
{
|
||||
$booking = $this->request([]);
|
||||
|
||||
// The data request went out, the offer waits for the address, the clarification hold runs independently.
|
||||
$context = CaseContext::of($booking->fresh());
|
||||
$this->assertSame([BookingStatus::Reserved, Booking::HOLD_CLARIFICATION], [$booking->status, $booking->hold_purpose]);
|
||||
$this->assertSame(StepState::Waiting, app(Hold::class)->state($context));
|
||||
$this->assertSame(DataRequest::OPEN, $booking->openDataRequest()->status);
|
||||
$this->assertSame(ActivityState::Later, $this->activity($booking, 'offer')->state);
|
||||
$this->assertSame(ActivityState::Waiting, $this->activity($booking, 'contact')->state);
|
||||
|
||||
// The hold expires; the request stays open for its details (only offer holds expire).
|
||||
$this->travel(125)->minutes();
|
||||
$this->artisan('bookings:expire-holds')->assertSuccessful();
|
||||
$this->assertSame(BookingStatus::Reserved, $booking->fresh()->status);
|
||||
$this->assertSame(StepState::Done, app(Hold::class)->state(CaseContext::of($booking->fresh())));
|
||||
|
||||
// The guest answers later; the offer becomes ready and goes out with a new offer hold.
|
||||
app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.street' => 'Lindenallee 12', 'guest.postal_code' => '10115', 'guest.city' => 'Berlin', 'guest.country' => 'DE'], FactSource::GuestLink);
|
||||
$booking->refresh();
|
||||
$this->assertSame([BookingStatus::OfferSent, Booking::HOLD_OFFER], [$booking->status, $booking->hold_purpose]);
|
||||
$this->assertSame(DataRequest::COMPLETED, $booking->dataRequests()->sole()->status);
|
||||
}
|
||||
|
||||
public function test_an_external_address_check_waits_without_holding_back_the_offer(): void
|
||||
{
|
||||
config([
|
||||
'process.modules' => [...config('process.modules'), AddressVerification::class],
|
||||
'process.models' => [...config('process.models'), 'a1.offer_address' => [1 => A1WithAddressCheck::class]],
|
||||
]);
|
||||
$this->app->forgetInstance(ProcessCatalogue::class);
|
||||
AddressVerification::$serviceAvailable = false;
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE'], automatic: false);
|
||||
$plan = ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer_address', 'variant' => 'address_check']);
|
||||
$booking->forceFill(['profile' => [...$booking->profile, 'plan' => $plan->toArray()], 'processing_mode' => 'automatic'])->saveQuietly();
|
||||
|
||||
$result = app(ProcessRunner::class)->advance($booking->fresh());
|
||||
|
||||
$this->assertTrue($result->ran('offer.binding'), 'the offer does not depend on the address check');
|
||||
$this->assertSame(ActivityState::Waiting, $this->activity($booking, 'address_check')->state);
|
||||
$this->assertSame([], app(ProcessCatalogue::class)->problems(), 'a new module and a variant fit without changing other models');
|
||||
}
|
||||
|
||||
public function test_a_finished_case_of_a_retired_version_stays_readable(): void
|
||||
{
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
$plan = $booking->profile['plan'];
|
||||
// An older release: model version 0 and a module that no longer exists.
|
||||
$plan['model_version'] = 0;
|
||||
$plan['modules'] = ['intake.record' => 1, 'old.welcome_call' => 1, ...$plan['modules']];
|
||||
$plan['labels']['old.welcome_call'] = 'Begrüßungsanruf';
|
||||
$booking->forceFill(['status' => BookingStatus::Declined, 'profile' => [...$booking->profile, 'plan' => $plan]])->saveQuietly();
|
||||
|
||||
$activities = CaseActivities::for($booking->fresh());
|
||||
|
||||
$this->assertTrue(ProcessPlan::of($booking->fresh())->isHistoric());
|
||||
$this->assertSame('Begrüßungsanruf (frühere Fassung)', collect($activities)->firstWhere('key', 'old.welcome_call')->label);
|
||||
$this->assertSame('done', collect($activities)->firstWhere('key', 'offer')->state->value);
|
||||
$this->assertNotNull(CaseActivities::situation($booking->fresh()));
|
||||
}
|
||||
|
||||
public function test_a_tester_only_variant_is_refused_for_real_cases(): void
|
||||
{
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
|
||||
$this->expectExceptionMessage('nur im Prozess-Tester');
|
||||
ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer', 'variant' => 'loyalty']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $address
|
||||
*/
|
||||
private function request(array $address, bool $automatic = true): Booking
|
||||
{
|
||||
if (! $automatic) {
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'manual']]);
|
||||
}
|
||||
|
||||
return app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', ...$address]);
|
||||
}
|
||||
|
||||
private function activity(Booking $booking, string $key): Activity
|
||||
{
|
||||
return collect(CaseActivities::for($booking->fresh()))->firstWhere('key', $key) ?? $this->fail("No activity {$key}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\Property;
|
||||
use App\Process\AdvanceResult;
|
||||
use App\Process\Modules\Dependency;
|
||||
use App\Process\Modules\StepState;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessRunner;
|
||||
use App\Process\StepResult;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\Support\Process\FakeModel;
|
||||
use Tests\Support\Process\FakeModule;
|
||||
use Tests\Support\Process\FakeModuleA;
|
||||
use Tests\Support\Process\FakeModuleB;
|
||||
use Tests\Support\Process\FakeModuleC;
|
||||
use Tests\Support\Process\FakeModuleD;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Requirement T1 (docs/Prozessarchitektur/Architektur/02 §7): hard and soft dependencies, independent and conditional
|
||||
* steps, re-evaluation after every state change, idempotence, failures and the suspension of outward steps (O4) –
|
||||
* with scripted modules, so each rule is shown on its own.
|
||||
*/
|
||||
#[Group('runner')]
|
||||
class ProcessRunnerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Booking $booking;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(PropertySeeder::class);
|
||||
FakeModule::reset();
|
||||
config([
|
||||
'process.modules' => [...config('process.modules'), FakeModuleA::class, FakeModuleB::class, FakeModuleC::class, FakeModuleD::class],
|
||||
'process.models' => [...config('process.models'), 'test.model' => [1 => FakeModel::class]],
|
||||
]);
|
||||
$this->app->forgetInstance(ProcessCatalogue::class);
|
||||
$this->booking = Booking::factory()->for(Property::sole())->reserved()->create(['intake' => 'inquiry']);
|
||||
$this->plan('standard');
|
||||
}
|
||||
|
||||
public function test_a_hard_dependency_holds_the_step_back_while_an_independent_step_goes_on(): void
|
||||
{
|
||||
FakeModule::$script = [
|
||||
'test.a' => ['state' => StepState::Waiting, 'due' => false],
|
||||
'test.b' => ['requires' => [Dependency::hard('test.a')]],
|
||||
'test.c' => [],
|
||||
];
|
||||
|
||||
$result = $this->advance();
|
||||
|
||||
$this->assertSame(['test.c'], FakeModule::$runs, 'the waiting step holds back only what depends on it hard');
|
||||
$this->assertSame(['Wartet auf: Testschritt test.a.'], $result->reasons('test.b'));
|
||||
}
|
||||
|
||||
public function test_a_hard_dependency_cannot_be_lifted_by_the_waiting_step(): void
|
||||
{
|
||||
// Whatever the waiting step declares, the dependent decides: hard is hard.
|
||||
FakeModule::$script = [
|
||||
'test.a' => ['state' => StepState::Problem, 'due' => false],
|
||||
'test.b' => ['requires' => [Dependency::hard('test.a')]],
|
||||
];
|
||||
|
||||
$this->advance();
|
||||
|
||||
$this->assertNotContains('test.b', FakeModule::$runs);
|
||||
}
|
||||
|
||||
public function test_a_soft_dependency_orders_steps_but_does_not_wait(): void
|
||||
{
|
||||
FakeModule::$script = [
|
||||
'test.a' => ['requires' => [Dependency::soft('test.c')]],
|
||||
'test.c' => [],
|
||||
];
|
||||
$this->advance();
|
||||
$this->assertSame(['test.c', 'test.a'], FakeModule::$runs, 'both due: the soft dependency goes first');
|
||||
|
||||
FakeModule::reset();
|
||||
FakeModule::$script = [
|
||||
'test.a' => ['requires' => [Dependency::soft('test.c')]],
|
||||
'test.c' => ['state' => StepState::Waiting, 'due' => false],
|
||||
];
|
||||
$this->advance();
|
||||
$this->assertSame(['test.a'], FakeModule::$runs, 'the soft dependency waits: the step goes on');
|
||||
}
|
||||
|
||||
public function test_readiness_is_determined_anew_after_every_state_change(): void
|
||||
{
|
||||
FakeModule::$script = [
|
||||
// A's run completes what B needs and makes C superfluous.
|
||||
'test.a' => ['run' => function (): ?StepResult {
|
||||
FakeModule::$script['test.b']['state'] = StepState::Open;
|
||||
FakeModule::$script['test.c']['due'] = false;
|
||||
|
||||
return null;
|
||||
}],
|
||||
'test.b' => ['state' => StepState::Later, 'due' => true, 'requires' => [Dependency::hard('test.a')]],
|
||||
'test.c' => [],
|
||||
];
|
||||
|
||||
$this->advance();
|
||||
|
||||
$this->assertSame(['test.a', 'test.b'], FakeModule::$runs, 'B became ready after A; C was ready before A ran, but no longer afterwards');
|
||||
}
|
||||
|
||||
public function test_conditional_steps_and_switched_off_optional_steps_are_skipped(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => ['applies' => false], 'test.b' => [], 'test.c' => []];
|
||||
$this->plan('standard', ['test.c' => ['on' => false]]);
|
||||
|
||||
$this->advance();
|
||||
|
||||
// test.c is a fake module without the optional toggle: a mandatory step cannot be switched off.
|
||||
$this->assertSame(['test.b', 'test.c'], FakeModule::$runs);
|
||||
}
|
||||
|
||||
public function test_a_failing_step_is_reported_and_independent_steps_go_on(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => ['run' => fn () => FakeModule::fail()], 'test.b' => []];
|
||||
|
||||
$result = $this->advance();
|
||||
|
||||
$this->assertSame(['test.a', 'test.b'], FakeModule::$runs);
|
||||
$this->assertSame(['Technischer Fehler beim automatischen Weiterbearbeiten – bitte von Hand fortsetzen.'], $result->reasons('test.a'));
|
||||
$this->assertTrue($result->ran('test.b'));
|
||||
}
|
||||
|
||||
public function test_a_second_advance_has_no_effect(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => [], 'test.b' => []];
|
||||
$this->advance();
|
||||
FakeModule::$runs = [];
|
||||
|
||||
$this->advance();
|
||||
|
||||
$this->assertSame([], FakeModule::$runs, 'every step is done; nothing is due');
|
||||
}
|
||||
|
||||
public function test_a_step_runs_once_per_advance_even_if_it_stays_due(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => ['run' => fn (): StepResult => StepResult::blocked(['noch nicht'])]];
|
||||
|
||||
$result = $this->advance();
|
||||
|
||||
$this->assertSame(['test.a'], FakeModule::$runs);
|
||||
$this->assertSame(['noch nicht'], $result->reasons('test.a'));
|
||||
}
|
||||
|
||||
public function test_only_steps_that_declare_the_trigger_are_considered(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => []];
|
||||
|
||||
app(ProcessRunner::class)->advance($this->booking, 'request.created');
|
||||
|
||||
$this->assertSame([], FakeModule::$runs);
|
||||
}
|
||||
|
||||
public function test_a_variant_inserts_its_module_at_the_extension_point(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => [], 'test.b' => [], 'test.c' => [], 'test.d' => []];
|
||||
$this->plan('extra');
|
||||
|
||||
$this->advance();
|
||||
|
||||
$this->assertSame(['test.a', 'test.b', 'test.d', 'test.c'], FakeModule::$runs);
|
||||
}
|
||||
|
||||
public function test_an_open_portal_report_suspends_outward_steps_only(): void
|
||||
{
|
||||
FakeModule::$script = ['test.a' => ['outward' => true], 'test.b' => []];
|
||||
BookingTask::query()->create(['tenant_id' => $this->booking->tenant_id, 'booking_id' => $this->booking->id, 'kind' => BookingTaskKind::PortalCancellationReported, 'status' => BookingTaskStatus::Open, 'title' => 'Portal meldet Stornierung']);
|
||||
|
||||
$result = $this->advance();
|
||||
|
||||
$this->assertSame(['test.b'], FakeModule::$runs, 'internal steps go on (decision O4)');
|
||||
$this->assertStringContainsString('warten, bis die Meldung', $result->reasons('test.a')[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array<string, mixed>> $steps
|
||||
*/
|
||||
private function plan(string $variant, array $steps = []): void
|
||||
{
|
||||
$model = app(ProcessCatalogue::class)->model('test.model');
|
||||
$modules = array_fill_keys($model->modules($variant), 1);
|
||||
$plan = new ProcessPlan('test.model', 1, $variant, $modules, $steps, ProcessPlan::CONFIGURED);
|
||||
$this->booking->forceFill(['profile' => [...(array) $this->booking->profile, 'plan' => $plan->toArray()]])->saveQuietly();
|
||||
}
|
||||
|
||||
private function advance(): AdvanceResult
|
||||
{
|
||||
return app(ProcessRunner::class)->advance($this->booking->fresh(), 'test');
|
||||
}
|
||||
}
|
||||
@@ -323,9 +323,9 @@
|
||||
{
|
||||
"key": "offer",
|
||||
"label": "Angebot senden (automatisch)",
|
||||
"state": "open",
|
||||
"detail": "Zeitraum reserviert bis 23.10.2026, 18:30 Uhr",
|
||||
"action": "sendOffer"
|
||||
"state": "problem",
|
||||
"detail": "Der Zeitraum ist inzwischen belegt.",
|
||||
"action": null
|
||||
},
|
||||
{
|
||||
"key": "acceptance",
|
||||
|
||||
@@ -6,6 +6,7 @@ # Beabsichtigte Abweichungen von der v0.11-Referenz
|
||||
|---|---|---|---|---|
|
||||
| I-001 | Ereignistypen der Schrittdetails kommen aus der Moduldefinition statt aus `ActivityDetails::EVENT_TYPES` | eine Quelle (Architektur `02` §7.7) | `ActivityDetailsTest` unverändert grün | keine (gleiches Ergebnis) |
|
||||
| I-002 | Offene, einem Vorgang zugeordnete Portalmeldung (Storno/Änderung) setzt automatische **Außenwirkungen** aus: Unterlagen, Erinnerungen, Anreiseinformation | Entscheidung O4 | `PortalReportSuspendsAutomationTest` | `portal_mail_cancellation` (nur wenn Außenwirkungen anstanden) |
|
||||
| I-003 | Zeit-Actions (`ExpireReservations`, `RequestCaseData::handOver`) rufen danach `ProcessRunner::advance` für den Vorgang | K1: Wiederaufnahme ohne neuen Auslöser | `RunnerResumesAfterDeadlineTest` | keine erwartet |
|
||||
| I-004 | Angebotsschritt bei belegtem Zeitraum = `problem` | Fehler F-001 | `OfferModuleTest::taken_dates_are_a_problem` | `a1_dates_taken.answer_dates_taken` |
|
||||
| I-005 | Detail des Angebotsschritts zeigt den tatsächlichen Reservierungszustand | Fehler F-002 | `OfferModuleTest::expired_hold_is_not_shown_as_reserved` | `a1_dates_taken.*`, `a1_missing_address.clarification_expired`, `a1_missing_address.first_reminder` |
|
||||
| I-003 | ~~Zeit-Actions rufen danach `advance`~~ – **entfällt**: `bookings:auto-offers` bewertet offene Anfragen alle 5 Minuten über den Runner neu; `ExpireReservations` und `handOver` machen keinen Schritt bereit | – | – | – |
|
||||
| I-004 | Angebotsschritt bei belegtem Zeitraum = `problem`, ohne Senden-Aktion | Fehler F-001 | `BehaviourComparisonTest` (`a1_dates_taken`, neu aufgenommen) | `a1_dates_taken.answer_dates_taken` |
|
||||
| I-005 | Detail des Angebotsschritts zeigt den tatsächlichen Reservierungszustand | Fehler F-002 | `BehaviourComparisonTest` (`a1_dates_taken`), `OngoingCaseRegressionTest` (`legacy_migration_offer`) | `a1_dates_taken.answer_dates_taken`; Bestandsfall `legacy_migration_offer` |
|
||||
| I-006 | Technischer Fehler eines automatischen Schritts: einheitlicher Text „Technischer Fehler beim automatischen Weiterbearbeiten – bitte von Hand fortsetzen.“ je Schritt (vorher je Aufrufer eigener Text); `CreateReservation` behält seinen Text, wenn der Runner selbst scheitert | ein Ablaufkern | `ProcessRunnerTest::test_a_failing_step_is_reported_and_independent_steps_go_on` | keine (kein Fehlerfall in der Referenz) |
|
||||
@@ -2356,7 +2356,7 @@
|
||||
[
|
||||
"offer",
|
||||
"open",
|
||||
"Zeitraum reserviert bis 25.10.2026, 17:00 Uhr",
|
||||
"Reservierung abgelaufen am 25.10.2026, 17:00 Uhr – Zeitraum nicht reserviert",
|
||||
"sendOffer"
|
||||
],
|
||||
[
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
use App\Enums\CaseType;
|
||||
use App\Process\Models\InquiryModel;
|
||||
use App\Process\Models\Point;
|
||||
use App\Process\Models\Variant;
|
||||
|
||||
/**
|
||||
* An A1 model with a variant that inserts the address check at AfterGuestIdentified – only in tests.
|
||||
*/
|
||||
final class A1WithAddressCheck extends InquiryModel
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'a1.offer_address';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Angebot mit Adressprüfung (Test)';
|
||||
}
|
||||
|
||||
public static function description(): string
|
||||
{
|
||||
return 'Test';
|
||||
}
|
||||
|
||||
public static function caseTypes(): array
|
||||
{
|
||||
return [CaseType::A1];
|
||||
}
|
||||
|
||||
public static function fixes(): array
|
||||
{
|
||||
return ['pre_reservation' => true];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [Variant::make('standard', 'Standard'), Variant::make('address_check', 'Mit Adressprüfung')->insert(Point::AfterGuestIdentified, 'guest.address_verification')];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
use App\Enums\ActivityState;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Dependency;
|
||||
use App\Process\Modules\Module;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Process\Modules\RunsAutomatically;
|
||||
use App\Process\Modules\StepState;
|
||||
use App\Process\StepResult;
|
||||
|
||||
/**
|
||||
* The test case of the module criteria (docs/Prozessarchitektur/Architektur/02 §2.1): an external address check is a
|
||||
* module of its own – own result, own effect (network), own waiting state, own evidence, switchable per channel. Not
|
||||
* part of the application; it shows that such a module fits at an existing extension point without changing other
|
||||
* models, and that its waiting does not hold back steps that do not depend on it.
|
||||
*/
|
||||
final class AddressVerification extends Module implements RunsAutomatically
|
||||
{
|
||||
public static bool $serviceAvailable = true;
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'guest.address_verification';
|
||||
}
|
||||
|
||||
public static function definition(): ModuleDefinition
|
||||
{
|
||||
return new ModuleDefinition(
|
||||
label: 'Anschrift extern prüfen',
|
||||
purpose: 'Prüft die Anschrift bei einem Adressdienst.',
|
||||
phase: 'P01',
|
||||
requires: [Dependency::hard('guest.details')],
|
||||
effects: ['network', 'case_write'],
|
||||
waits: ['time'],
|
||||
triggers: ['automation'],
|
||||
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
|
||||
modes: ['automatic'],
|
||||
points: ['after_guest_identified'],
|
||||
);
|
||||
}
|
||||
|
||||
public function activities(CaseContext $case): array
|
||||
{
|
||||
$state = $this->state($case);
|
||||
|
||||
return [new Activity('address_check', 'Anschrift extern prüfen', $state === StepState::Done ? ActivityState::Done : ActivityState::Waiting, self::$serviceAvailable ? null : 'Adressdienst nicht erreichbar – neuer Versuch später')];
|
||||
}
|
||||
|
||||
public function state(CaseContext $case): ?StepState
|
||||
{
|
||||
return self::$serviceAvailable ? StepState::Done : StepState::Waiting;
|
||||
}
|
||||
|
||||
public function due(CaseContext $case): bool
|
||||
{
|
||||
return ! self::$serviceAvailable;
|
||||
}
|
||||
|
||||
public function blockers(CaseContext $case): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function run(CaseContext $case): StepResult
|
||||
{
|
||||
return StepResult::blocked(['Adressdienst nicht erreichbar.']);
|
||||
}
|
||||
|
||||
public function isOutward(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
use App\Enums\CaseType;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Process\Models\Point;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\Models\Responsibilities;
|
||||
use App\Process\Models\Step;
|
||||
use App\Process\Models\Variant;
|
||||
|
||||
/**
|
||||
* A model of the four fake modules for the runner tests, with one extension point.
|
||||
*/
|
||||
final class FakeModel extends ProcessModel
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.model';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Testmodell';
|
||||
}
|
||||
|
||||
public static function description(): string
|
||||
{
|
||||
return 'Testmodell';
|
||||
}
|
||||
|
||||
public static function caseTypes(): array
|
||||
{
|
||||
return [CaseType::A1];
|
||||
}
|
||||
|
||||
public static function intakes(): array
|
||||
{
|
||||
return [IntakeKind::Inquiry];
|
||||
}
|
||||
|
||||
public static function responsibilities(): Responsibilities
|
||||
{
|
||||
return Responsibilities::of([]);
|
||||
}
|
||||
|
||||
public function steps(): array
|
||||
{
|
||||
return [Step::module('test.a'), Step::module('test.b'), Step::point(Point::BeforePriceFixing), Step::module('test.c')];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [Variant::make('standard', 'Standard'), Variant::make('extra', 'Mit D')->insert(Point::BeforePriceFixing, 'test.d')];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
use App\Enums\ActivityState;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Dependency;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Process\Modules\ProcessModule;
|
||||
use App\Process\Modules\RunsAutomatically;
|
||||
use App\Process\Modules\StepState;
|
||||
use App\Process\StepResult;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* A scriptable module for the runner tests: its state, dependencies and what its run does come from a shared script,
|
||||
* so the tests can model waiting, failing and state changes during a round. Subclasses only give the key.
|
||||
*/
|
||||
abstract class FakeModule implements ProcessModule, RunsAutomatically
|
||||
{
|
||||
/**
|
||||
* @var array<string, array{state?: StepState, due?: bool, requires?: list<Dependency>, run?: callable(): ?StepResult, outward?: bool, applies?: bool}>
|
||||
*/
|
||||
public static array $script = [];
|
||||
|
||||
/** @var list<string> */
|
||||
public static array $runs = [];
|
||||
|
||||
public static function reset(): void
|
||||
{
|
||||
self::$script = [];
|
||||
self::$runs = [];
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function definition(): ModuleDefinition
|
||||
{
|
||||
return new ModuleDefinition(
|
||||
label: 'Testschritt '.static::key(),
|
||||
purpose: 'Test',
|
||||
phase: 'P01',
|
||||
requires: self::$script[static::key()]['requires'] ?? [],
|
||||
triggers: ['automation', 'test'],
|
||||
modes: ['automatic'],
|
||||
);
|
||||
}
|
||||
|
||||
public function applies(CaseContext $case): bool
|
||||
{
|
||||
return array_key_exists(static::key(), self::$script) && (self::$script[static::key()]['applies'] ?? true);
|
||||
}
|
||||
|
||||
public function activities(CaseContext $case): array
|
||||
{
|
||||
$state = $this->state($case) ?? StepState::Open;
|
||||
|
||||
return [new Activity(static::key(), static::key(), ActivityState::from($state->value))];
|
||||
}
|
||||
|
||||
public function state(CaseContext $case): ?StepState
|
||||
{
|
||||
return self::$script[static::key()]['state'] ?? StepState::Open;
|
||||
}
|
||||
|
||||
public function due(CaseContext $case): bool
|
||||
{
|
||||
return self::$script[static::key()]['due'] ?? ($this->state($case) === StepState::Open);
|
||||
}
|
||||
|
||||
public function blockers(CaseContext $case): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function run(CaseContext $case): StepResult
|
||||
{
|
||||
self::$runs[] = static::key();
|
||||
$run = self::$script[static::key()]['run'] ?? null;
|
||||
$result = $run === null ? null : $run();
|
||||
if ($result === null) {
|
||||
self::$script[static::key()]['state'] = StepState::Done;
|
||||
}
|
||||
|
||||
return $result ?? StepResult::ran();
|
||||
}
|
||||
|
||||
public function isOutward(): bool
|
||||
{
|
||||
return self::$script[static::key()]['outward'] ?? false;
|
||||
}
|
||||
|
||||
public static function fail(): never
|
||||
{
|
||||
throw new RuntimeException('Testfehler');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
final class FakeModuleA extends FakeModule
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.a';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
final class FakeModuleB extends FakeModule
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.b';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
final class FakeModuleC extends FakeModule
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.c';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
final class FakeModuleD extends FakeModule
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.d';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user