1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Refactor dependency checking in DependencyTest.php

This commit is contained in:
Benjamin Beganović 2024-02-29 17:36:52 +01:00
parent 0380a14232
commit 33e8743024

View File

@ -64,7 +64,7 @@ class DependencyTest extends TestCase
Cart::class,
]);
$this->assertEquals(Purchase::$steps, $results);
$this->assertEquals(Purchase::defaultSteps(), $results);
$results = $this->sort([
RegisterOrLogin::class,
@ -100,14 +100,18 @@ class DependencyTest extends TestCase
private function checkDependencies(array $steps): array
{
$dependencies = Purchase::$dependencies;
$step_order = array_flip($steps);
$stepOrder = array_flip($steps);
$errors = [];
foreach ($steps as $step) {
$dependent = $dependencies[$step]['dependencies'] ?? [];
if (!empty($dependent) && !array_intersect($dependent, $steps)) {
$errors[] = "Dependency error: [$step] requires at least one of its dependencies [" . implode(', ', $dependent) . "] in the list.";
}
foreach ($dependent as $dependency) {
if (in_array($dependency, $steps) && $step_order[$dependency] > $step_order[$step]) {
if (in_array($dependency, $steps) && $stepOrder[$dependency] > $stepOrder[$step]) {
$errors[] = "Dependency error: $step depends on $dependency";
}
}
@ -121,7 +125,7 @@ class DependencyTest extends TestCase
$errors = $this->checkDependencies($dependencies);
if (count($errors)) {
return Purchase::$steps;
return Purchase::defaultSteps();
}
return [Setup::class, ...$dependencies, Submit::class]; // Note: Re-index if you're doing any index-based checking/comparision.