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> $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'); } }