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>
102 lines
2.8 KiB
PHP
102 lines
2.8 KiB
PHP
<?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');
|
|
}
|
|
}
|