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,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');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user