From b5c6c840a6ad7dba801e6964ec1e0b9a78848e0a Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Mon, 1 Jun 2026 19:59:43 +0200 Subject: [PATCH] Rename Form Flow classes to follow Symfony native names Align all Form Flow class names with Symfony's native naming convention (Flow instead of Flow). The namespace root is unchanged; only class/file names changed. Block prefixes change accordingly. Add CHANGELOG entries: 0.3.1 (Symfony 8.0 support) and 0.4.0 (rename). Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 29 +++ src/Form/Flow/AbstractButtonFlowType.php | 14 ++ src/Form/Flow/AbstractFlowButtonType.php | 14 -- .../Flow/{FlowButton.php => ButtonFlow.php} | 2 +- src/Form/Flow/ButtonFlowBuilder.php | 16 ++ ...nInterface.php => ButtonFlowInterface.php} | 2 +- src/Form/Flow/ButtonFlowTypeInterface.php | 12 ++ src/Form/Flow/FlowButtonBuilder.php | 16 -- src/Form/Flow/FlowButtonTypeInterface.php | 12 -- src/Form/Flow/FormFlow.php | 14 +- src/Form/Flow/FormFlowBuilder.php | 24 +-- src/Form/Flow/FormFlowBuilderInterface.php | 10 +- src/Form/Flow/FormFlowConfigInterface.php | 4 +- .../{FlowCursor.php => FormFlowCursor.php} | 24 +-- src/Form/Flow/FormFlowInterface.php | 4 +- ...lowStepBuilder.php => StepFlowBuilder.php} | 30 +-- ...php => StepFlowBuilderConfigInterface.php} | 6 +- ...erface.php => StepFlowConfigInterface.php} | 2 +- .../{FlowStepNode.php => StepFlowNode.php} | 4 +- ...{FlowButtonType.php => ButtonFlowType.php} | 8 +- ...{FlowFinishType.php => FinishFlowType.php} | 12 +- src/Form/Flow/Type/FormFlowType.php | 12 +- ...avigatorType.php => NavigatorFlowType.php} | 10 +- .../{FlowNextType.php => NextFlowType.php} | 12 +- ...wPreviousType.php => PreviousFlowType.php} | 12 +- .../{FlowResetType.php => ResetFlowType.php} | 8 +- src/Form/ResolvedFormType.php | 8 +- tests/Fixtures/Flow/FirstStepSkippedType.php | 4 +- tests/Fixtures/Flow/GroupingStepsFlowType.php | 4 +- tests/Fixtures/Flow/LastStepSkippedType.php | 4 +- tests/Fixtures/Flow/NestedStepsFlowType.php | 4 +- .../Fixtures/Flow/UserSignUpNavigatorType.php | 8 +- ...wCursorTest.php => FormFlowCursorTest.php} | 182 +++++++++--------- tests/Flow/FormFlowTest.php | 22 +-- ...wStepNodeTest.php => StepFlowNodeTest.php} | 44 ++--- .../FormFlowBasic/Form/Type/MultistepType.php | 4 +- .../App/FormFlowBasic/Form/Type/Step2Type.php | 4 +- 37 files changed, 315 insertions(+), 286 deletions(-) create mode 100644 src/Form/Flow/AbstractButtonFlowType.php delete mode 100644 src/Form/Flow/AbstractFlowButtonType.php rename src/Form/Flow/{FlowButton.php => ButtonFlow.php} (96%) create mode 100644 src/Form/Flow/ButtonFlowBuilder.php rename src/Form/Flow/{FlowButtonInterface.php => ButtonFlowInterface.php} (93%) create mode 100644 src/Form/Flow/ButtonFlowTypeInterface.php delete mode 100644 src/Form/Flow/FlowButtonBuilder.php delete mode 100644 src/Form/Flow/FlowButtonTypeInterface.php rename src/Form/Flow/{FlowCursor.php => FormFlowCursor.php} (89%) rename src/Form/Flow/{FlowStepBuilder.php => StepFlowBuilder.php} (73%) rename src/Form/Flow/{FlowStepBuilderInterface.php => StepFlowBuilderConfigInterface.php} (85%) rename src/Form/Flow/{FlowStepConfigInterface.php => StepFlowConfigInterface.php} (96%) rename src/Form/Flow/{FlowStepNode.php => StepFlowNode.php} (98%) rename src/Form/Flow/Type/{FlowButtonType.php => ButtonFlowType.php} (84%) rename src/Form/Flow/Type/{FlowFinishType.php => FinishFlowType.php} (59%) rename src/Form/Flow/Type/{FlowNavigatorType.php => NavigatorFlowType.php} (75%) rename src/Form/Flow/Type/{FlowNextType.php => NextFlowType.php} (59%) rename src/Form/Flow/Type/{FlowPreviousType.php => PreviousFlowType.php} (62%) rename src/Form/Flow/Type/{FlowResetType.php => ResetFlowType.php} (71%) rename tests/Flow/{FlowCursorTest.php => FormFlowCursorTest.php} (63%) rename tests/Flow/{FlowStepNodeTest.php => StepFlowNodeTest.php} (90%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f89ddb2..13b4f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,35 @@ CHANGELOG ========= +0.4.0 +----- + * [Breaking Changes] Renamed the Form Flow classes to follow Symfony's native naming convention (`Flow` instead of `Flow`). The `Yceruto\FormFlowBundle\Form\Flow` namespace is unchanged; only class names changed: + + | Before | After | + |----------------------------|----------------------------------| + | `AbstractFlowButtonType` | `AbstractButtonFlowType` | + | `FlowButton` | `ButtonFlow` | + | `FlowButtonBuilder` | `ButtonFlowBuilder` | + | `FlowButtonInterface` | `ButtonFlowInterface` | + | `FlowButtonTypeInterface` | `ButtonFlowTypeInterface` | + | `FlowCursor` | `FormFlowCursor` | + | `FlowStepNode` | `StepFlowNode` | + | `FlowStepBuilder` | `StepFlowBuilder` | + | `FlowStepBuilderInterface` | `StepFlowBuilderConfigInterface` | + | `FlowStepConfigInterface` | `StepFlowConfigInterface` | + | `Type\FlowButtonType` | `Type\ButtonFlowType` | + | `Type\FlowFinishType` | `Type\FinishFlowType` | + | `Type\FlowNavigatorType` | `Type\NavigatorFlowType` | + | `Type\FlowNextType` | `Type\NextFlowType` | + | `Type\FlowPreviousType` | `Type\PreviousFlowType` | + | `Type\FlowResetType` | `Type\ResetFlowType` | + + * [Breaking Changes] As a consequence of the type renames, the form type block prefixes changed: `flow_button` → `button_flow`, `flow_finish` → `finish_flow`, `flow_navigator` → `navigator_flow`, `flow_next` → `next_flow`, `flow_previous` → `previous_flow`, `flow_reset` → `reset_flow`. Update any custom form themes that reference the old block names. + +0.3.1 +----- + * Add support for Symfony 8.0 + 0.3.0 ----- * Add support for grouping and nested steps in `FormFlowType` diff --git a/src/Form/Flow/AbstractButtonFlowType.php b/src/Form/Flow/AbstractButtonFlowType.php new file mode 100644 index 0000000..2e76700 --- /dev/null +++ b/src/Form/Flow/AbstractButtonFlowType.php @@ -0,0 +1,14 @@ +getFormConfig()); + } +} diff --git a/src/Form/Flow/FlowButtonInterface.php b/src/Form/Flow/ButtonFlowInterface.php similarity index 93% rename from src/Form/Flow/FlowButtonInterface.php rename to src/Form/Flow/ButtonFlowInterface.php index b3230a0..feb0b6b 100644 --- a/src/Form/Flow/FlowButtonInterface.php +++ b/src/Form/Flow/ButtonFlowInterface.php @@ -5,7 +5,7 @@ use Symfony\Component\Form\ClickableInterface; use Symfony\Component\Form\FormInterface; -interface FlowButtonInterface extends FormInterface, ClickableInterface +interface ButtonFlowInterface extends FormInterface, ClickableInterface { /** * Executes the callable handler. diff --git a/src/Form/Flow/ButtonFlowTypeInterface.php b/src/Form/Flow/ButtonFlowTypeInterface.php new file mode 100644 index 0000000..4e57eed --- /dev/null +++ b/src/Form/Flow/ButtonFlowTypeInterface.php @@ -0,0 +1,12 @@ +getFormConfig()); - } -} diff --git a/src/Form/Flow/FlowButtonTypeInterface.php b/src/Form/Flow/FlowButtonTypeInterface.php deleted file mode 100644 index d5a2730..0000000 --- a/src/Form/Flow/FlowButtonTypeInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -move(static fn (FlowCursor $cursor) => $cursor->getPreviousStep())) { + if (!$this->move(static fn (FormFlowCursor $cursor) => $cursor->getPreviousStep())) { throw new RuntimeException('Cannot determine previous step.'); } } public function moveNext(): void { - if (!$this->move(static fn (FlowCursor $cursor) => $cursor->getNextStep())) { + if (!$this->move(static fn (FormFlowCursor $cursor) => $cursor->getNextStep())) { throw new RuntimeException('Cannot determine next step.'); } } @@ -108,7 +108,7 @@ public function getStepForm(): static return $this->newStepForm(); } - public function getCursor(): FlowCursor + public function getCursor(): FormFlowCursor { return $this->cursor; } @@ -123,7 +123,7 @@ public function isFinished(): bool return $this->finished; } - public function getClickedButton(): FlowButtonInterface|FormInterface|ClickableInterface|null + public function getClickedButton(): ButtonFlowInterface|FormInterface|ClickableInterface|null { return parent::getClickedButton() ?? $this->clickedFlowButton; } @@ -149,7 +149,7 @@ private function setClickedFlowButton(mixed $submittedData, FormInterface $form) continue; } - if (!$child instanceof FlowButtonInterface) { + if (!$child instanceof ButtonFlowInterface) { continue; } diff --git a/src/Form/Flow/FormFlowBuilder.php b/src/Form/Flow/FormFlowBuilder.php index fd8478d..c46a5ca 100644 --- a/src/Form/Flow/FormFlowBuilder.php +++ b/src/Form/Flow/FormFlowBuilder.php @@ -19,38 +19,38 @@ class FormFlowBuilder extends FormBuilder implements FormFlowBuilderInterface { /** - * @var array + * @var array */ private array $steps = []; private array $initialOptions = []; private DataStorageInterface $dataStorage; private StepAccessorInterface $stepAccessor; - public function createStepGroup(string $name): FlowStepBuilderInterface + public function createStepGroup(string $name): StepFlowBuilderConfigInterface { if ($this->locked) { throw new BadMethodCallException('FormFlowBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowConfigInterface instance.'); } - return (new FlowStepBuilder($name))->setGroup(true); + return (new StepFlowBuilder($name))->setGroup(true); } - public function createStep(string $name, string $type = FormType::class, array $options = []): FlowStepBuilderInterface + public function createStep(string $name, string $type = FormType::class, array $options = []): StepFlowBuilderConfigInterface { if ($this->locked) { throw new BadMethodCallException('FormFlowBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowConfigInterface instance.'); } - return new FlowStepBuilder($name, $type, $options); + return new StepFlowBuilder($name, $type, $options); } - public function addStep(FlowStepBuilderInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static + public function addStep(StepFlowBuilderConfigInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static { if ($this->locked) { throw new BadMethodCallException('FormFlowBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowConfigInterface instance.'); } - if ($name instanceof FlowStepBuilderInterface) { + if ($name instanceof StepFlowBuilderConfigInterface) { $this->steps[$name->getName()] = $name; return $this; @@ -90,7 +90,7 @@ public function hasStep(string $name): bool return false; } - public function getStep(string $name): FlowStepBuilderInterface + public function getStep(string $name): StepFlowBuilderConfigInterface { if (isset($this->steps[$name])) { return $this->steps[$name]; @@ -222,7 +222,7 @@ private function createFormFlow(): FormFlowInterface throw new InvalidArgumentException('Steps not configured.'); } - uasort($this->steps, static fn (FlowStepBuilderInterface $a, FlowStepBuilderInterface $b) => $b->getPriority() <=> $a->getPriority()); + uasort($this->steps, static fn (StepFlowBuilderConfigInterface $a, StepFlowBuilderConfigInterface $b) => $b->getPriority() <=> $a->getPriority()); $config = $this->getFormConfig(); $currentStep = $this->resolveCurrentStep(); @@ -230,7 +230,7 @@ private function createFormFlow(): FormFlowInterface $step = $this->getStep($currentStep); $this->add($step->getName(), $step->getType(), $step->getOptions()); - $cursor = new FlowCursor($config->getSteps(), $currentStep); + $cursor = new FormFlowCursor($config->getSteps(), $currentStep); $this->pruneActionButtons($this, $cursor); return new FormFlow($config, $cursor); @@ -273,7 +273,7 @@ private function resolveFirstStep(?array $steps = null): string throw new LogicException('No navigable step found. All steps are groups or skipped.'); } - private function pruneActionButtons(FormBuilderInterface $builder, FlowCursor $cursor): void + private function pruneActionButtons(FormBuilderInterface $builder, FormFlowCursor $cursor): void { foreach ($builder->all() as $child) { if ($child->count() > 0) { @@ -282,7 +282,7 @@ private function pruneActionButtons(FormBuilderInterface $builder, FlowCursor $c continue; } - if (!$child instanceof FlowButtonBuilder || !\is_callable($include = $child->getOption('include_if'))) { + if (!$child instanceof ButtonFlowBuilder || !\is_callable($include = $child->getOption('include_if'))) { continue; } diff --git a/src/Form/Flow/FormFlowBuilderInterface.php b/src/Form/Flow/FormFlowBuilderInterface.php index 02fb3db..911c385 100644 --- a/src/Form/Flow/FormFlowBuilderInterface.php +++ b/src/Form/Flow/FormFlowBuilderInterface.php @@ -15,17 +15,17 @@ interface FormFlowBuilderInterface extends FormBuilderInterface, FormFlowConfigI /** * Creates a new step builder marked as a group. */ - public function createStepGroup(string $name): FlowStepBuilderInterface; + public function createStepGroup(string $name): StepFlowBuilderConfigInterface; /** * Creates a new step builder. */ - public function createStep(string $name, string $type = FormType::class, array $options = []): FlowStepBuilderInterface; + public function createStep(string $name, string $type = FormType::class, array $options = []): StepFlowBuilderConfigInterface; /** * Adds a step to the form flow. */ - public function addStep(FlowStepBuilderInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static; + public function addStep(StepFlowBuilderConfigInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static; /** * Removes a step from the form flow. @@ -35,12 +35,12 @@ public function removeStep(string $name): static; /** * Returns a step builder by name. */ - public function getStep(string $name): FlowStepBuilderInterface; + public function getStep(string $name): StepFlowBuilderConfigInterface; /** * Returns all step builders. * - * @return array + * @return array */ public function getSteps(): array; diff --git a/src/Form/Flow/FormFlowConfigInterface.php b/src/Form/Flow/FormFlowConfigInterface.php index ae4f22c..c126a82 100644 --- a/src/Form/Flow/FormFlowConfigInterface.php +++ b/src/Form/Flow/FormFlowConfigInterface.php @@ -19,12 +19,12 @@ public function hasStep(string $name): bool; /** * Returns the step with the given name. */ - public function getStep(string $name): FlowStepConfigInterface; + public function getStep(string $name): StepFlowConfigInterface; /** * Returns all steps. * - * @return array + * @return array */ public function getSteps(): array; diff --git a/src/Form/Flow/FlowCursor.php b/src/Form/Flow/FormFlowCursor.php similarity index 89% rename from src/Form/Flow/FlowCursor.php rename to src/Form/Flow/FormFlowCursor.php index 3edee74..39767a5 100644 --- a/src/Form/Flow/FlowCursor.php +++ b/src/Form/Flow/FormFlowCursor.php @@ -5,18 +5,18 @@ use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\LogicException; -class FlowCursor +class FormFlowCursor { - /** @var list */ + /** @var list */ private array $roots; - /** @var array */ + /** @var array */ private array $stepMap; /** @var list */ private array $steps; - private FlowStepNode $currentStep; + private StepFlowNode $currentStep; /** - * @param array|list $steps Step configs or a flat list of step names + * @param array|list $steps Step configs or a flat list of step names * @param string $currentStep The name of the current step */ public function __construct( @@ -26,9 +26,9 @@ public function __construct( $first = reset($steps); if (\is_string($first)) { - $this->roots = FlowStepNode::fromArray($steps); - } elseif ($first instanceof FlowStepConfigInterface) { - $this->roots = FlowStepNode::fromConfig($steps); + $this->roots = StepFlowNode::fromArray($steps); + } elseif ($first instanceof StepFlowConfigInterface) { + $this->roots = StepFlowNode::fromConfig($steps); } else { throw new InvalidArgumentException('The $steps argument must be a list of step names or a list of step configs.'); } @@ -91,7 +91,7 @@ public function getParentStep(): ?string */ public function getChildSteps(): array { - return array_map(static fn (FlowStepNode $node) => $node->getName(), $this->currentStep->getChildren()); + return array_map(static fn (StepFlowNode $node) => $node->getName(), $this->currentStep->getChildren()); } public function getFirstStep(): string @@ -195,12 +195,12 @@ public function canMoveNext(): bool return false; } - public function getCurrentStepNode(): FlowStepNode + public function getCurrentStepNode(): StepFlowNode { return $this->currentStep; } - public function getStepNode(string $name): FlowStepNode + public function getStepNode(string $name): StepFlowNode { if (!isset($this->stepMap[$name])) { throw new InvalidArgumentException(\sprintf('Step "%s" does not exist. Available steps are: "%s".', $name, implode('", "', $this->steps))); @@ -210,7 +210,7 @@ public function getStepNode(string $name): FlowStepNode } /** - * @return list + * @return list */ public function getRootStepNodes(): array { diff --git a/src/Form/Flow/FormFlowInterface.php b/src/Form/Flow/FormFlowInterface.php index c6cffd2..e1d45f8 100644 --- a/src/Form/Flow/FormFlowInterface.php +++ b/src/Form/Flow/FormFlowInterface.php @@ -11,7 +11,7 @@ interface FormFlowInterface extends FormInterface /** * Returns the button used to submit the form. */ - public function getClickedButton(): FlowButtonInterface|FormInterface|ClickableInterface|null; + public function getClickedButton(): ButtonFlowInterface|FormInterface|ClickableInterface|null; /** * Resets the flow by clearing stored data and setting the cursor to the initial step. @@ -48,7 +48,7 @@ public function getStepForm(): static; /** * Returns the cursor that tracks the current position in the flow. */ - public function getCursor(): FlowCursor; + public function getCursor(): FormFlowCursor; /** * Returns the configuration for this flow. diff --git a/src/Form/Flow/FlowStepBuilder.php b/src/Form/Flow/StepFlowBuilder.php similarity index 73% rename from src/Form/Flow/FlowStepBuilder.php rename to src/Form/Flow/StepFlowBuilder.php index 326ab60..c78ba53 100644 --- a/src/Form/Flow/FlowStepBuilder.php +++ b/src/Form/Flow/StepFlowBuilder.php @@ -7,12 +7,12 @@ use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\FormTypeInterface; -class FlowStepBuilder implements FlowStepBuilderInterface +class StepFlowBuilder implements StepFlowBuilderConfigInterface { private bool $locked = false; private int $priority = 0; private ?\Closure $skip = null; - /** @var array */ + /** @var array */ private array $children = []; private bool $group = false; @@ -34,7 +34,7 @@ public function getName(): string public function getType(): string { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } return $this->type; @@ -43,7 +43,7 @@ public function getType(): string public function getOptions(): array { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } return $this->options; @@ -57,7 +57,7 @@ public function getPriority(): int public function setPriority(int $priority): static { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } $this->priority = $priority; @@ -82,7 +82,7 @@ public function isSkipped(mixed $data): bool public function setSkip(?\Closure $skip): static { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } $this->skip = $skip; @@ -93,7 +93,7 @@ public function setSkip(?\Closure $skip): static public function setGroup(bool $group): static { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } $this->group = $group; @@ -106,19 +106,19 @@ public function isGroup(): bool return $this->group; } - public function addStep(FlowStepBuilderInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static + public function addStep(StepFlowBuilderConfigInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } - if ($name instanceof FlowStepBuilderInterface) { + if ($name instanceof StepFlowBuilderConfigInterface) { $this->children[$name->getName()] = $name; return $this; } - $this->children[$name] = (new FlowStepBuilder($name, $type, $options)) + $this->children[$name] = (new StepFlowBuilder($name, $type, $options)) ->setSkip($skip ? $skip(...) : null) ->setPriority($priority); @@ -152,7 +152,7 @@ public function hasStep(string $name): bool return false; } - public function getStep(string $name): FlowStepConfigInterface + public function getStep(string $name): StepFlowConfigInterface { if (isset($this->children[$name])) { return $this->children[$name]; @@ -169,17 +169,17 @@ public function getStep(string $name): FlowStepConfigInterface throw new InvalidArgumentException(\sprintf('Sub step "%s" does not exist in "%s" step.', $name, $this->name)); } - public function getStepConfig(): FlowStepConfigInterface + public function getStepConfig(): StepFlowConfigInterface { if ($this->locked) { - throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + throw new BadMethodCallException('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); } // This method should be idempotent, so clone the builder $config = clone $this; $config->locked = true; - uasort($config->children, static fn (FlowStepBuilderInterface $a, FlowStepBuilderInterface $b) => $b->getPriority() <=> $a->getPriority()); + uasort($config->children, static fn (StepFlowBuilderConfigInterface $a, StepFlowBuilderConfigInterface $b) => $b->getPriority() <=> $a->getPriority()); foreach ($config->children as $name => $step) { $config->children[$name] = $step->getStepConfig(); diff --git a/src/Form/Flow/FlowStepBuilderInterface.php b/src/Form/Flow/StepFlowBuilderConfigInterface.php similarity index 85% rename from src/Form/Flow/FlowStepBuilderInterface.php rename to src/Form/Flow/StepFlowBuilderConfigInterface.php index 605d5b4..b007ce4 100644 --- a/src/Form/Flow/FlowStepBuilderInterface.php +++ b/src/Form/Flow/StepFlowBuilderConfigInterface.php @@ -4,7 +4,7 @@ use Symfony\Component\Form\Extension\Core\Type\FormType; -interface FlowStepBuilderInterface extends FlowStepConfigInterface +interface StepFlowBuilderConfigInterface extends StepFlowConfigInterface { /** * Returns the form type class name for the step. @@ -47,7 +47,7 @@ public function addStep(self|string $name, string $type = FormType::class, array public function removeStep(string $name): static; /** - * Returns a FlowStepConfigInterface instance for the step. + * Returns a StepFlowConfigInterface instance for the step. */ - public function getStepConfig(): FlowStepConfigInterface; + public function getStepConfig(): StepFlowConfigInterface; } diff --git a/src/Form/Flow/FlowStepConfigInterface.php b/src/Form/Flow/StepFlowConfigInterface.php similarity index 96% rename from src/Form/Flow/FlowStepConfigInterface.php rename to src/Form/Flow/StepFlowConfigInterface.php index 90879b1..aa406a2 100644 --- a/src/Form/Flow/FlowStepConfigInterface.php +++ b/src/Form/Flow/StepFlowConfigInterface.php @@ -2,7 +2,7 @@ namespace Yceruto\FormFlowBundle\Form\Flow; -interface FlowStepConfigInterface +interface StepFlowConfigInterface { /** * Returns the name of the step. diff --git a/src/Form/Flow/FlowStepNode.php b/src/Form/Flow/StepFlowNode.php similarity index 98% rename from src/Form/Flow/FlowStepNode.php rename to src/Form/Flow/StepFlowNode.php index 68c80f9..500746d 100644 --- a/src/Form/Flow/FlowStepNode.php +++ b/src/Form/Flow/StepFlowNode.php @@ -7,7 +7,7 @@ /** * Represents a node in the step flow tree (forest graph). */ -class FlowStepNode +class StepFlowNode { /** @var list */ private array $children = []; @@ -50,7 +50,7 @@ public static function fromArray(array $steps): array /** * Builds a forest from step configurations. * - * @param array $steps Ordered step configs + * @param array $steps Ordered step configs * * @return list */ diff --git a/src/Form/Flow/Type/FlowButtonType.php b/src/Form/Flow/Type/ButtonFlowType.php similarity index 84% rename from src/Form/Flow/Type/FlowButtonType.php rename to src/Form/Flow/Type/ButtonFlowType.php index b9dcc3b..00f64a4 100644 --- a/src/Form/Flow/Type/FlowButtonType.php +++ b/src/Form/Flow/Type/ButtonFlowType.php @@ -6,13 +6,13 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonTypeInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowTypeInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; /** * A submit button with a callable handler for a form flow. */ -class FlowButtonType extends AbstractType implements FlowButtonTypeInterface +class ButtonFlowType extends AbstractType implements ButtonFlowTypeInterface { public function configureOptions(OptionsResolver $resolver): void { @@ -27,7 +27,7 @@ public function configureOptions(OptionsResolver $resolver): void ->allowedTypes('null', 'array', 'callable') ->normalize(function (Options $options, mixed $value) { if (\is_array($value)) { - return fn (FlowCursor $cursor): bool => \in_array($cursor->getCurrentStep(), $value, true); + return fn (FormFlowCursor $cursor): bool => \in_array($cursor->getCurrentStep(), $value, true); } return $value; diff --git a/src/Form/Flow/Type/FlowFinishType.php b/src/Form/Flow/Type/FinishFlowType.php similarity index 59% rename from src/Form/Flow/Type/FlowFinishType.php rename to src/Form/Flow/Type/FinishFlowType.php index 13b070a..cfb5168 100644 --- a/src/Form/Flow/Type/FlowFinishType.php +++ b/src/Form/Flow/Type/FinishFlowType.php @@ -4,12 +4,12 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowButtonType; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\AbstractButtonFlowType; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; use Yceruto\FormFlowBundle\Form\Flow\FormFlowInterface; -class FlowFinishType extends AbstractFlowButtonType +class FinishFlowType extends AbstractButtonFlowType { public function buildForm(FormBuilderInterface $builder, array $options): void { @@ -19,8 +19,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'handler' => fn (mixed $data, FlowButtonInterface $button, FormFlowInterface $flow) => $flow->reset(), - 'include_if' => fn (FlowCursor $cursor): bool => $cursor->isLastStep(), + 'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->reset(), + 'include_if' => fn (FormFlowCursor $cursor): bool => $cursor->isLastStep(), ]); } } diff --git a/src/Form/Flow/Type/FormFlowType.php b/src/Form/Flow/Type/FormFlowType.php index 7b2968c..6e8fdac 100644 --- a/src/Form/Flow/Type/FormFlowType.php +++ b/src/Form/Flow/Type/FormFlowType.php @@ -16,9 +16,9 @@ use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowType; use Yceruto\FormFlowBundle\Form\Flow\DataStorage\DataStorageInterface; use Yceruto\FormFlowBundle\Form\Flow\DataStorage\NullDataStorage; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; -use Yceruto\FormFlowBundle\Form\Flow\FlowStepConfigInterface; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\StepFlowConfigInterface; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; use Yceruto\FormFlowBundle\Form\Flow\FormFlowInterface; use Yceruto\FormFlowBundle\Form\Flow\StepAccessor\PropertyPathStepAccessor; @@ -90,17 +90,17 @@ public function onPreSubmit(FormEvent $event): void $flow = $event->getForm(); $button = $flow->getClickedButton(); - if ($button instanceof FlowButtonInterface && $button->isClearSubmission()) { + if ($button instanceof ButtonFlowInterface && $button->isClearSubmission()) { $event->setData([]); } } /** - * @param array $steps + * @param array $steps * * @return array> */ - private function buildStepsVars(array $steps, FlowCursor $cursor, mixed $viewData, int $level = 0): array + private function buildStepsVars(array $steps, FormFlowCursor $cursor, mixed $viewData, int $level = 0): array { $tree = []; $index = 0; diff --git a/src/Form/Flow/Type/FlowNavigatorType.php b/src/Form/Flow/Type/NavigatorFlowType.php similarity index 75% rename from src/Form/Flow/Type/FlowNavigatorType.php rename to src/Form/Flow/Type/NavigatorFlowType.php index e39cd34..f2a1bb9 100644 --- a/src/Form/Flow/Type/FlowNavigatorType.php +++ b/src/Form/Flow/Type/NavigatorFlowType.php @@ -9,16 +9,16 @@ /** * A navigator type that defines default buttons to interact with a form flow. */ -class FlowNavigatorType extends AbstractType +class NavigatorFlowType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->add('previous', FlowPreviousType::class); - $builder->add('next', FlowNextType::class); - $builder->add('finish', FlowFinishType::class); + $builder->add('previous', PreviousFlowType::class); + $builder->add('next', NextFlowType::class); + $builder->add('finish', FinishFlowType::class); if ($options['with_reset']) { - $builder->add('reset', FlowResetType::class); + $builder->add('reset', ResetFlowType::class); } } diff --git a/src/Form/Flow/Type/FlowNextType.php b/src/Form/Flow/Type/NextFlowType.php similarity index 59% rename from src/Form/Flow/Type/FlowNextType.php rename to src/Form/Flow/Type/NextFlowType.php index 25d15fc..ec2244d 100644 --- a/src/Form/Flow/Type/FlowNextType.php +++ b/src/Form/Flow/Type/NextFlowType.php @@ -4,12 +4,12 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowButtonType; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\AbstractButtonFlowType; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; use Yceruto\FormFlowBundle\Form\Flow\FormFlowInterface; -class FlowNextType extends AbstractFlowButtonType +class NextFlowType extends AbstractButtonFlowType { public function buildForm(FormBuilderInterface $builder, array $options): void { @@ -19,8 +19,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'handler' => fn (mixed $data, FlowButtonInterface $button, FormFlowInterface $flow) => $flow->moveNext(), - 'include_if' => fn (FlowCursor $cursor): bool => $cursor->canMoveNext(), + 'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->moveNext(), + 'include_if' => fn (FormFlowCursor $cursor): bool => $cursor->canMoveNext(), ]); } } diff --git a/src/Form/Flow/Type/FlowPreviousType.php b/src/Form/Flow/Type/PreviousFlowType.php similarity index 62% rename from src/Form/Flow/Type/FlowPreviousType.php rename to src/Form/Flow/Type/PreviousFlowType.php index 72e45c1..a328da7 100644 --- a/src/Form/Flow/Type/FlowPreviousType.php +++ b/src/Form/Flow/Type/PreviousFlowType.php @@ -4,12 +4,12 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowButtonType; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\AbstractButtonFlowType; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; use Yceruto\FormFlowBundle\Form\Flow\FormFlowInterface; -class FlowPreviousType extends AbstractFlowButtonType +class PreviousFlowType extends AbstractButtonFlowType { public function buildForm(FormBuilderInterface $builder, array $options): void { @@ -19,8 +19,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'handler' => fn (mixed $data, FlowButtonInterface $button, FormFlowInterface $flow) => $flow->movePrevious($button->getViewData()), - 'include_if' => fn (FlowCursor $cursor): bool => $cursor->canMoveBack(), + 'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->movePrevious($button->getViewData()), + 'include_if' => fn (FormFlowCursor $cursor): bool => $cursor->canMoveBack(), 'clear_submission' => true, ]); } diff --git a/src/Form/Flow/Type/FlowResetType.php b/src/Form/Flow/Type/ResetFlowType.php similarity index 71% rename from src/Form/Flow/Type/FlowResetType.php rename to src/Form/Flow/Type/ResetFlowType.php index dd21ccf..ead1dd3 100644 --- a/src/Form/Flow/Type/FlowResetType.php +++ b/src/Form/Flow/Type/ResetFlowType.php @@ -4,11 +4,11 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowButtonType; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonInterface; +use Yceruto\FormFlowBundle\Form\Flow\AbstractButtonFlowType; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowInterface; use Yceruto\FormFlowBundle\Form\Flow\FormFlowInterface; -class FlowResetType extends AbstractFlowButtonType +class ResetFlowType extends AbstractButtonFlowType { public function buildForm(FormBuilderInterface $builder, array $options): void { @@ -18,7 +18,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'handler' => fn (mixed $data, FlowButtonInterface $button, FormFlowInterface $flow) => $flow->reset(), + 'handler' => fn (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) => $flow->reset(), 'clear_submission' => true, ]); } diff --git a/src/Form/ResolvedFormType.php b/src/Form/ResolvedFormType.php index 7f33fae..60ad27e 100644 --- a/src/Form/ResolvedFormType.php +++ b/src/Form/ResolvedFormType.php @@ -9,8 +9,8 @@ use Symfony\Component\Form\ResolvedFormType as SymfonyResolvedFormType; use Symfony\Component\Form\ResolvedFormTypeInterface; use Symfony\Component\OptionsResolver\Exception\ExceptionInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonBuilder; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonTypeInterface; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowBuilder; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowTypeInterface; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilder; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; use Yceruto\FormFlowBundle\Form\Flow\FormFlowTypeInterface; @@ -41,8 +41,8 @@ public function createBuilder(FormFactoryInterface $factory, string $name, array protected function newBuilder(string $name, ?string $dataClass, FormFactoryInterface $factory, array $options): FormBuilderInterface { - if ($this->innerType instanceof FlowButtonTypeInterface) { - return new FlowButtonBuilder($name, $options); + if ($this->innerType instanceof ButtonFlowTypeInterface) { + return new ButtonFlowBuilder($name, $options); } if ($this->innerType instanceof FormFlowTypeInterface) { diff --git a/tests/Fixtures/Flow/FirstStepSkippedType.php b/tests/Fixtures/Flow/FirstStepSkippedType.php index 2246ac1..6e12a78 100644 --- a/tests/Fixtures/Flow/FirstStepSkippedType.php +++ b/tests/Fixtures/Flow/FirstStepSkippedType.php @@ -6,7 +6,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowType; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNavigatorType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NavigatorFlowType; class FirstStepSkippedType extends AbstractFlowType { @@ -16,7 +16,7 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options) $builder->addStep('step2', TextType::class); $builder->addStep('step3', TextType::class); - $builder->add('navigator', FlowNavigatorType::class); + $builder->add('navigator', NavigatorFlowType::class); } public function configureOptions(OptionsResolver $resolver): void diff --git a/tests/Fixtures/Flow/GroupingStepsFlowType.php b/tests/Fixtures/Flow/GroupingStepsFlowType.php index a9eb536..50cf1f2 100644 --- a/tests/Fixtures/Flow/GroupingStepsFlowType.php +++ b/tests/Fixtures/Flow/GroupingStepsFlowType.php @@ -7,7 +7,7 @@ use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowType; use Yceruto\FormFlowBundle\Form\Flow\DataStorage\InMemoryDataStorage; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNavigatorType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NavigatorFlowType; /** * a(group) => [a1, a2], b, c(group) => [c1]. @@ -28,7 +28,7 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options) ->addStep('c1', TextType::class) ); - $builder->add('navigator', FlowNavigatorType::class, ['with_reset' => true]); + $builder->add('navigator', NavigatorFlowType::class, ['with_reset' => true]); } public function configureOptions(OptionsResolver $resolver): void diff --git a/tests/Fixtures/Flow/LastStepSkippedType.php b/tests/Fixtures/Flow/LastStepSkippedType.php index 2df34f7..8467449 100644 --- a/tests/Fixtures/Flow/LastStepSkippedType.php +++ b/tests/Fixtures/Flow/LastStepSkippedType.php @@ -7,7 +7,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowType; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNavigatorType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NavigatorFlowType; class LastStepSkippedType extends AbstractFlowType { @@ -16,7 +16,7 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options) $builder->addStep('step1', TextType::class); $builder->addStep('step2', FormType::class, [], static fn () => true); - $builder->add('navigator', FlowNavigatorType::class, [ + $builder->add('navigator', NavigatorFlowType::class, [ 'with_reset' => true, ]); } diff --git a/tests/Fixtures/Flow/NestedStepsFlowType.php b/tests/Fixtures/Flow/NestedStepsFlowType.php index 7f44c04..f426fbc 100644 --- a/tests/Fixtures/Flow/NestedStepsFlowType.php +++ b/tests/Fixtures/Flow/NestedStepsFlowType.php @@ -8,7 +8,7 @@ use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowType; use Yceruto\FormFlowBundle\Form\Flow\DataStorage\InMemoryDataStorage; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNavigatorType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NavigatorFlowType; class NestedStepsFlowType extends AbstractFlowType { @@ -33,7 +33,7 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options) ) ->addStep('stepC', TextType::class); - $builder->add('navigator', FlowNavigatorType::class, ['with_reset' => true]); + $builder->add('navigator', NavigatorFlowType::class, ['with_reset' => true]); } public function configureOptions(OptionsResolver $resolver): void diff --git a/tests/Fixtures/Flow/UserSignUpNavigatorType.php b/tests/Fixtures/Flow/UserSignUpNavigatorType.php index ff66e4e..04e0952 100644 --- a/tests/Fixtures/Flow/UserSignUpNavigatorType.php +++ b/tests/Fixtures/Flow/UserSignUpNavigatorType.php @@ -5,14 +5,14 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNavigatorType; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNextType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NavigatorFlowType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NextFlowType; class UserSignUpNavigatorType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->add('skip', FlowNextType::class, [ + $builder->add('skip', NextFlowType::class, [ 'clear_submission' => true, 'include_if' => ['professional'], ]); @@ -27,6 +27,6 @@ public function configureOptions(OptionsResolver $resolver): void public function getParent(): string { - return FlowNavigatorType::class; + return NavigatorFlowType::class; } } diff --git a/tests/Flow/FlowCursorTest.php b/tests/Flow/FormFlowCursorTest.php similarity index 63% rename from tests/Flow/FlowCursorTest.php rename to tests/Flow/FormFlowCursorTest.php index ad88229..c846f6c 100644 --- a/tests/Flow/FlowCursorTest.php +++ b/tests/Flow/FormFlowCursorTest.php @@ -4,24 +4,24 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Form\Exception\InvalidArgumentException; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; -use Yceruto\FormFlowBundle\Form\Flow\FlowStepBuilder; -use Yceruto\FormFlowBundle\Form\Flow\FlowStepConfigInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\StepFlowBuilder; +use Yceruto\FormFlowBundle\Form\Flow\StepFlowConfigInterface; -class FlowCursorTest extends TestCase +class FormFlowCursorTest extends TestCase { private const array STEPS = ['personal', 'professional', 'account']; /** * @param list $names * - * @return array + * @return array */ private static function createSteps(array $names = self::STEPS): array { $configs = []; foreach ($names as $name) { - $configs[$name] = (new FlowStepBuilder($name))->getStepConfig(); + $configs[$name] = (new StepFlowBuilder($name))->getStepConfig(); } return $configs; @@ -29,20 +29,20 @@ private static function createSteps(array $names = self::STEPS): array private static function createNestedSteps(): array { - $personal = (new FlowStepBuilder('personal')) + $personal = (new StepFlowBuilder('personal')) ->addStep('name') ->addStep('contact'); return [ - 'intro' => (new FlowStepBuilder('intro'))->getStepConfig(), + 'intro' => (new StepFlowBuilder('intro'))->getStepConfig(), 'personal' => $personal->getStepConfig(), - 'summary' => (new FlowStepBuilder('summary'))->getStepConfig(), + 'summary' => (new StepFlowBuilder('summary'))->getStepConfig(), ]; } public function testConstructorWithValidStep() { - $cursor = new FlowCursor(self::createSteps(), 'personal'); + $cursor = new FormFlowCursor(self::createSteps(), 'personal'); $this->assertSame(self::STEPS, $cursor->getSteps()); $this->assertSame('personal', $cursor->getCurrentStep()); @@ -53,26 +53,26 @@ public function testConstructorWithInvalidStep() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Step "invalid" does not exist. Available steps are: "personal", "professional", "account".'); - new FlowCursor(self::createSteps(), 'invalid'); + new FormFlowCursor(self::createSteps(), 'invalid'); } public function testConstructorWithDeprecatedStringList() { - $cursor = new FlowCursor(self::STEPS, 'personal'); + $cursor = new FormFlowCursor(self::STEPS, 'personal'); $this->assertSame(self::STEPS, $cursor->getSteps()); } public function testGetSteps() { - $cursor = new FlowCursor(self::createSteps(), 'personal'); + $cursor = new FormFlowCursor(self::createSteps(), 'personal'); $this->assertSame(self::STEPS, $cursor->getSteps()); } public function testGetTotalSteps() { - $cursor = new FlowCursor(self::createSteps(), 'personal'); + $cursor = new FormFlowCursor(self::createSteps(), 'personal'); $this->assertSame(3, $cursor->getTotalSteps()); } @@ -81,19 +81,19 @@ public function testGetStepIndex() { $steps = self::createSteps(); - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertSame(0, $cursor->getStepIndex()); - $cursor = new FlowCursor($steps, 'professional'); + $cursor = new FormFlowCursor($steps, 'professional'); $this->assertSame(1, $cursor->getStepIndex()); - $cursor = new FlowCursor($steps, 'account'); + $cursor = new FormFlowCursor($steps, 'account'); $this->assertSame(2, $cursor->getStepIndex()); } public function testGetFirstStep() { - $cursor = new FlowCursor(self::createSteps(), 'professional'); + $cursor = new FormFlowCursor(self::createSteps(), 'professional'); $this->assertSame('personal', $cursor->getFirstStep()); } @@ -103,28 +103,28 @@ public function testGetPrevStep() $steps = self::createSteps(); // First step has no previous step - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertNull($cursor->getPreviousStep()); // Middle step has previous step - $cursor = new FlowCursor($steps, 'professional'); + $cursor = new FormFlowCursor($steps, 'professional'); $this->assertSame('personal', $cursor->getPreviousStep()); // Last step has previous step - $cursor = new FlowCursor($steps, 'account'); + $cursor = new FormFlowCursor($steps, 'account'); $this->assertSame('professional', $cursor->getPreviousStep()); } public function testGetCurrentStep() { - $cursor = new FlowCursor(self::createSteps(), 'professional'); + $cursor = new FormFlowCursor(self::createSteps(), 'professional'); $this->assertSame('professional', $cursor->getCurrentStep()); } public function testWithCurrentStep() { - $cursor = new FlowCursor(self::createSteps(), 'personal'); + $cursor = new FormFlowCursor(self::createSteps(), 'personal'); $newCursor = $cursor->withCurrentStep('professional'); @@ -144,21 +144,21 @@ public function testGetNextStep() $steps = self::createSteps(); // First step has next step - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertSame('professional', $cursor->getNextStep()); // Middle step has next step - $cursor = new FlowCursor($steps, 'professional'); + $cursor = new FormFlowCursor($steps, 'professional'); $this->assertSame('account', $cursor->getNextStep()); // Last step has no next step - $cursor = new FlowCursor($steps, 'account'); + $cursor = new FormFlowCursor($steps, 'account'); $this->assertNull($cursor->getNextStep()); } public function testGetLastStep() { - $cursor = new FlowCursor(self::createSteps(), 'personal'); + $cursor = new FormFlowCursor(self::createSteps(), 'personal'); $this->assertSame('account', $cursor->getLastStep()); } @@ -168,11 +168,11 @@ public function testIsFirstStep() $steps = self::createSteps(); // First step - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertTrue($cursor->isFirstStep()); // Not first step - $cursor = new FlowCursor($steps, 'professional'); + $cursor = new FormFlowCursor($steps, 'professional'); $this->assertFalse($cursor->isFirstStep()); } @@ -181,11 +181,11 @@ public function testIsLastStep() $steps = self::createSteps(); // Not last step - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertFalse($cursor->isLastStep()); // Last step - $cursor = new FlowCursor($steps, 'account'); + $cursor = new FormFlowCursor($steps, 'account'); $this->assertTrue($cursor->isLastStep()); } @@ -194,15 +194,15 @@ public function testCanMovePreviousStep() $steps = self::createSteps(); // First position cannot move a previous step - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertFalse($cursor->canMoveBack()); // Middle position can move a previous step - $cursor = new FlowCursor($steps, 'professional'); + $cursor = new FormFlowCursor($steps, 'professional'); $this->assertTrue($cursor->canMoveBack()); // Last step can move a previous step - $cursor = new FlowCursor($steps, 'account'); + $cursor = new FormFlowCursor($steps, 'account'); $this->assertTrue($cursor->canMoveBack()); } @@ -211,22 +211,22 @@ public function testCanMoveNext() $steps = self::createSteps(); // First position can move next step - $cursor = new FlowCursor($steps, 'personal'); + $cursor = new FormFlowCursor($steps, 'personal'); $this->assertTrue($cursor->canMoveNext()); // Middle position can move next step - $cursor = new FlowCursor($steps, 'professional'); + $cursor = new FormFlowCursor($steps, 'professional'); $this->assertTrue($cursor->canMoveNext()); // Last position cannot move the next step - $cursor = new FlowCursor($steps, 'account'); + $cursor = new FormFlowCursor($steps, 'account'); $this->assertFalse($cursor->canMoveNext()); } public function testCursorWithSingleStep() { $steps = ['single']; - $cursor = new FlowCursor(self::createSteps($steps), 'single'); + $cursor = new FormFlowCursor(self::createSteps($steps), 'single'); $this->assertSame('single', $cursor->getCurrentStep()); $this->assertTrue($cursor->isFirstStep()); @@ -244,7 +244,7 @@ public function testCursorWithSingleStep() public function testNestedStepsAreFlattened() { - $cursor = new FlowCursor(self::createNestedSteps(), 'intro'); + $cursor = new FormFlowCursor(self::createNestedSteps(), 'intro'); $this->assertSame(['intro', 'personal', 'name', 'contact', 'summary'], $cursor->getSteps()); $this->assertSame(5, $cursor->getTotalSteps()); @@ -257,27 +257,27 @@ public function testNavigationWithNestedSteps() // Forward: intro → personal → name → contact → summary // Backward: summary → contact → name → personal → intro - $cursor = new FlowCursor($nestedSteps, 'intro'); + $cursor = new FormFlowCursor($nestedSteps, 'intro'); $this->assertTrue($cursor->isFirstStep()); $this->assertNull($cursor->getPreviousStep()); $this->assertSame('personal', $cursor->getNextStep()); - $cursor = new FlowCursor($nestedSteps, 'personal'); + $cursor = new FormFlowCursor($nestedSteps, 'personal'); $this->assertSame('intro', $cursor->getPreviousStep()); $this->assertSame('name', $cursor->getNextStep()); $this->assertSame(1, $cursor->getStepIndex()); - $cursor = new FlowCursor($nestedSteps, 'name'); + $cursor = new FormFlowCursor($nestedSteps, 'name'); $this->assertSame('personal', $cursor->getPreviousStep()); $this->assertSame('contact', $cursor->getNextStep()); $this->assertSame(2, $cursor->getStepIndex()); - $cursor = new FlowCursor($nestedSteps, 'contact'); + $cursor = new FormFlowCursor($nestedSteps, 'contact'); $this->assertSame('name', $cursor->getPreviousStep()); $this->assertSame('summary', $cursor->getNextStep()); $this->assertSame(3, $cursor->getStepIndex()); - $cursor = new FlowCursor($nestedSteps, 'summary'); + $cursor = new FormFlowCursor($nestedSteps, 'summary'); $this->assertTrue($cursor->isLastStep()); $this->assertSame('contact', $cursor->getPreviousStep()); $this->assertNull($cursor->getNextStep()); @@ -286,19 +286,19 @@ public function testNavigationWithNestedSteps() public function testNestedStepsWithMultipleForests() { - $personal = (new FlowStepBuilder('personal')) + $personal = (new StepFlowBuilder('personal')) ->addStep('name') ->addStep('email'); - $work = (new FlowStepBuilder('work')) + $work = (new StepFlowBuilder('work')) ->addStep('company') ->addStep('role'); - $cursor = new FlowCursor([ - 'intro' => (new FlowStepBuilder('intro'))->getStepConfig(), + $cursor = new FormFlowCursor([ + 'intro' => (new StepFlowBuilder('intro'))->getStepConfig(), 'personal' => $personal->getStepConfig(), - 'middle' => (new FlowStepBuilder('middle'))->getStepConfig(), + 'middle' => (new StepFlowBuilder('middle'))->getStepConfig(), 'work' => $work->getStepConfig(), - 'summary' => (new FlowStepBuilder('summary'))->getStepConfig(), + 'summary' => (new StepFlowBuilder('summary'))->getStepConfig(), ], 'intro'); $this->assertSame(['intro', 'personal', 'name', 'email', 'middle', 'work', 'company', 'role', 'summary'], $cursor->getSteps()); @@ -312,26 +312,26 @@ public function testInvalidStepInNestedStructure() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Step "invalid" does not exist. Available steps are: "intro", "personal", "name", "contact", "summary".'); - new FlowCursor(self::createNestedSteps(), 'invalid'); + new FormFlowCursor(self::createNestedSteps(), 'invalid'); } public function testStringKeyNestedStepsWithDepth() { - $position = (new FlowStepBuilder('position')) + $position = (new StepFlowBuilder('position')) ->addStep('title') ->addStep('department'); - $work = (new FlowStepBuilder('work')) + $work = (new StepFlowBuilder('work')) ->addStep('company') ->addStep($position); - $personal = (new FlowStepBuilder('personal')) + $personal = (new StepFlowBuilder('personal')) ->addStep('name') ->addStep('contact'); - $cursor = new FlowCursor([ - 'intro' => (new FlowStepBuilder('intro'))->getStepConfig(), + $cursor = new FormFlowCursor([ + 'intro' => (new StepFlowBuilder('intro'))->getStepConfig(), 'personal' => $personal->getStepConfig(), 'work' => $work->getStepConfig(), - 'summary' => (new FlowStepBuilder('summary'))->getStepConfig(), + 'summary' => (new StepFlowBuilder('summary'))->getStepConfig(), ], 'intro'); $this->assertSame([ @@ -344,21 +344,21 @@ public function testStringKeyNestedStepsWithDepth() public function testGetCurrentNode() { - $cursor = new FlowCursor(self::createNestedSteps(), 'name'); + $cursor = new FormFlowCursor(self::createNestedSteps(), 'name'); $this->assertSame('name', $cursor->getCurrentStepNode()->getName()); } public function testGetNode() { - $cursor = new FlowCursor(self::createNestedSteps(), 'intro'); + $cursor = new FormFlowCursor(self::createNestedSteps(), 'intro'); $this->assertSame('contact', $cursor->getStepNode('contact')->getName()); } public function testGetNodeThrowsForInvalidName() { - $cursor = new FlowCursor(self::createNestedSteps(), 'intro'); + $cursor = new FormFlowCursor(self::createNestedSteps(), 'intro'); $this->expectException(InvalidArgumentException::class); $cursor->getStepNode('invalid'); @@ -366,7 +366,7 @@ public function testGetNodeThrowsForInvalidName() public function testGetRoots() { - $cursor = new FlowCursor(self::createNestedSteps(), 'intro'); + $cursor = new FormFlowCursor(self::createNestedSteps(), 'intro'); $this->assertCount(3, $cursor->getRootStepNodes()); $this->assertSame('intro', $cursor->getRootStepNodes()[0]->getName()); @@ -376,24 +376,24 @@ public function testGetParentStep() { $steps = self::createNestedSteps(); - $this->assertNull((new FlowCursor($steps, 'intro'))->getParentStep()); - $this->assertNull((new FlowCursor($steps, 'personal'))->getParentStep()); - $this->assertSame('personal', (new FlowCursor($steps, 'name'))->getParentStep()); - $this->assertSame('personal', (new FlowCursor($steps, 'contact'))->getParentStep()); + $this->assertNull((new FormFlowCursor($steps, 'intro'))->getParentStep()); + $this->assertNull((new FormFlowCursor($steps, 'personal'))->getParentStep()); + $this->assertSame('personal', (new FormFlowCursor($steps, 'name'))->getParentStep()); + $this->assertSame('personal', (new FormFlowCursor($steps, 'contact'))->getParentStep()); } public function testGetChildSteps() { $steps = self::createNestedSteps(); - $this->assertSame([], (new FlowCursor($steps, 'intro'))->getChildSteps()); - $this->assertSame(['name', 'contact'], (new FlowCursor($steps, 'personal'))->getChildSteps()); - $this->assertSame([], (new FlowCursor($steps, 'name'))->getChildSteps()); + $this->assertSame([], (new FormFlowCursor($steps, 'intro'))->getChildSteps()); + $this->assertSame(['name', 'contact'], (new FormFlowCursor($steps, 'personal'))->getChildSteps()); + $this->assertSame([], (new FormFlowCursor($steps, 'name'))->getChildSteps()); } public function testWithCurrentStepSharesForest() { - $cursor = new FlowCursor(self::createNestedSteps(), 'intro'); + $cursor = new FormFlowCursor(self::createNestedSteps(), 'intro'); $newCursor = $cursor->withCurrentStep('summary'); $this->assertSame($cursor->getRootStepNodes(), $newCursor->getRootStepNodes()); @@ -404,74 +404,74 @@ public function testIsFirstStepWithGroupParent() { $steps = self::createGroupSteps(); - $this->assertTrue((new FlowCursor($steps, 'a1'))->isFirstStep()); - $this->assertFalse((new FlowCursor($steps, 'a2'))->isFirstStep()); - $this->assertFalse((new FlowCursor($steps, 'b'))->isFirstStep()); - $this->assertFalse((new FlowCursor($steps, 'c1'))->isFirstStep()); + $this->assertTrue((new FormFlowCursor($steps, 'a1'))->isFirstStep()); + $this->assertFalse((new FormFlowCursor($steps, 'a2'))->isFirstStep()); + $this->assertFalse((new FormFlowCursor($steps, 'b'))->isFirstStep()); + $this->assertFalse((new FormFlowCursor($steps, 'c1'))->isFirstStep()); } public function testIsLastStepWithGroupParent() { $steps = self::createGroupSteps(); - $this->assertTrue((new FlowCursor($steps, 'c1'))->isLastStep()); - $this->assertFalse((new FlowCursor($steps, 'b'))->isLastStep()); - $this->assertFalse((new FlowCursor($steps, 'a2'))->isLastStep()); - $this->assertFalse((new FlowCursor($steps, 'a1'))->isLastStep()); + $this->assertTrue((new FormFlowCursor($steps, 'c1'))->isLastStep()); + $this->assertFalse((new FormFlowCursor($steps, 'b'))->isLastStep()); + $this->assertFalse((new FormFlowCursor($steps, 'a2'))->isLastStep()); + $this->assertFalse((new FormFlowCursor($steps, 'a1'))->isLastStep()); } public function testCanMoveBackWithGroupParent() { $steps = self::createGroupSteps(); - $this->assertFalse((new FlowCursor($steps, 'a1'))->canMoveBack()); - $this->assertTrue((new FlowCursor($steps, 'a2'))->canMoveBack()); - $this->assertTrue((new FlowCursor($steps, 'b'))->canMoveBack()); - $this->assertTrue((new FlowCursor($steps, 'c1'))->canMoveBack()); + $this->assertFalse((new FormFlowCursor($steps, 'a1'))->canMoveBack()); + $this->assertTrue((new FormFlowCursor($steps, 'a2'))->canMoveBack()); + $this->assertTrue((new FormFlowCursor($steps, 'b'))->canMoveBack()); + $this->assertTrue((new FormFlowCursor($steps, 'c1'))->canMoveBack()); } public function testCanMoveNextWithGroupParent() { $steps = self::createGroupSteps(); - $this->assertFalse((new FlowCursor($steps, 'c1'))->canMoveNext()); - $this->assertTrue((new FlowCursor($steps, 'b'))->canMoveNext()); - $this->assertTrue((new FlowCursor($steps, 'a2'))->canMoveNext()); - $this->assertTrue((new FlowCursor($steps, 'a1'))->canMoveNext()); + $this->assertFalse((new FormFlowCursor($steps, 'c1'))->canMoveNext()); + $this->assertTrue((new FormFlowCursor($steps, 'b'))->canMoveNext()); + $this->assertTrue((new FormFlowCursor($steps, 'a2'))->canMoveNext()); + $this->assertTrue((new FormFlowCursor($steps, 'a1'))->canMoveNext()); } public function testGetFirstStepWithGroupRoot() { $steps = self::createGroupSteps(); - $this->assertSame('a1', (new FlowCursor($steps, 'b'))->getFirstStep()); + $this->assertSame('a1', (new FormFlowCursor($steps, 'b'))->getFirstStep()); } public function testGetLastStepWithGroupTail() { $steps = self::createGroupSteps(); - $this->assertSame('c1', (new FlowCursor($steps, 'b'))->getLastStep()); + $this->assertSame('c1', (new FormFlowCursor($steps, 'b'))->getLastStep()); } /** * Creates steps: a(group) -> [a1, a2], b, c(group) -> [c1] * - * @return array + * @return array */ private static function createGroupSteps(): array { - $a = (new FlowStepBuilder('a')) + $a = (new StepFlowBuilder('a')) ->setGroup(true) ->addStep('a1') ->addStep('a2'); - $c = (new FlowStepBuilder('c')) + $c = (new StepFlowBuilder('c')) ->setGroup(true) ->addStep('c1'); return [ 'a' => $a->getStepConfig(), - 'b' => (new FlowStepBuilder('b'))->getStepConfig(), + 'b' => (new StepFlowBuilder('b'))->getStepConfig(), 'c' => $c->getStepConfig(), ]; } diff --git a/tests/Flow/FormFlowTest.php b/tests/Flow/FormFlowTest.php index 26b6b00..d6c3d83 100644 --- a/tests/Flow/FormFlowTest.php +++ b/tests/Flow/FormFlowTest.php @@ -13,11 +13,11 @@ use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Validation; use Yceruto\FormFlowBundle\Form\Flow\DataStorage\InMemoryDataStorage; -use Yceruto\FormFlowBundle\Form\Flow\FlowButtonInterface; -use Yceruto\FormFlowBundle\Form\Flow\FlowCursor; +use Yceruto\FormFlowBundle\Form\Flow\ButtonFlowInterface; +use Yceruto\FormFlowBundle\Form\Flow\FormFlowCursor; use Yceruto\FormFlowBundle\Form\Flow\FormFlowInterface; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNextType; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowPreviousType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NextFlowType; +use Yceruto\FormFlowBundle\Form\Flow\Type\PreviousFlowType; use Yceruto\FormFlowBundle\Form\ResolvedFormTypeFactory; use Yceruto\FormFlowBundle\Tests\Fixtures\Flow\Data\UserSignUp; use Yceruto\FormFlowBundle\Tests\Fixtures\Flow\Extension\UserSignUpTypeExtension; @@ -349,11 +349,11 @@ public function testPreviousActionWithoutPurgeSubmission() $flow = $this->factory->create(UserSignUpType::class, $data); // previous action without purge submission - $flow->get('navigator')->add('previous', FlowPreviousType::class, [ + $flow->get('navigator')->add('previous', PreviousFlowType::class, [ 'validate' => false, 'validation_groups' => false, 'clear_submission' => false, - 'include_if' => static fn (FlowCursor $cursor) => $cursor->canMoveBack(), + 'include_if' => static fn (FormFlowCursor $cursor) => $cursor->canMoveBack(), ]); self::assertSame('professional', $flow->getCursor()->getCurrentStep()); @@ -555,7 +555,7 @@ public function testMoveBackToStep() $data->currentStep = 'account'; $flow = $this->factory->create(UserSignUpType::class, $data); - $flow->get('navigator')->add('back_to_step', FlowPreviousType::class, [ + $flow->get('navigator')->add('back_to_step', PreviousFlowType::class, [ 'validate' => false, 'validation_groups' => false, 'clear_submission' => false, @@ -675,7 +675,7 @@ public function testCannotModifyStepConfigAfterFormBuilding() $flow = $this->factory->create(UserSignUpType::class, new UserSignUp()); $this->expectException(BadMethodCallException::class); - $this->expectExceptionMessage('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.'); + $this->expectExceptionMessage('StepFlowBuilder methods cannot be accessed anymore once the builder is turned into a StepFlowConfigInterface instance.'); $flow->getConfig()->getStep('personal')->setPriority(0); } @@ -705,7 +705,7 @@ public function testViewVars() $flow = $this->factory->create(UserSignUpType::class, new UserSignUp()); $view = $flow->createView(); - self::assertInstanceOf(FlowCursor::class, $view->vars['cursor']); + self::assertInstanceOf(FormFlowCursor::class, $view->vars['cursor']); self::assertCount(3, $view->vars['steps']); self::assertSame(['personal', 'professional', 'account'], array_keys($view->vars['steps'])); self::assertSame('personal', $view->vars['steps']['personal']['name']); @@ -902,8 +902,8 @@ public function testHandleActionManually() public function testAddFormErrorOnActionHandling() { $flow = $this->factory->create(UserSignUpType::class, new UserSignUp()); - $flow->get('navigator')->add('next', FlowNextType::class, [ - 'handler' => static function (mixed $data, FlowButtonInterface $button, FormFlowInterface $flow) { + $flow->get('navigator')->add('next', NextFlowType::class, [ + 'handler' => static function (mixed $data, ButtonFlowInterface $button, FormFlowInterface $flow) { $flow->addError(new FormError('Action error')); }, ]); diff --git a/tests/Flow/FlowStepNodeTest.php b/tests/Flow/StepFlowNodeTest.php similarity index 90% rename from tests/Flow/FlowStepNodeTest.php rename to tests/Flow/StepFlowNodeTest.php index 82788e0..e8561bf 100644 --- a/tests/Flow/FlowStepNodeTest.php +++ b/tests/Flow/StepFlowNodeTest.php @@ -4,13 +4,13 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Form\Exception\LogicException; -use Yceruto\FormFlowBundle\Form\Flow\FlowStepBuilder; -use Yceruto\FormFlowBundle\Form\Flow\FlowStepNode; +use Yceruto\FormFlowBundle\Form\Flow\StepFlowBuilder; +use Yceruto\FormFlowBundle\Form\Flow\StepFlowNode; -class FlowStepNodeTest extends TestCase +class StepFlowNodeTest extends TestCase { /** - * @return list + * @return list */ private static function createNodes(array $steps): array { @@ -19,20 +19,20 @@ private static function createNodes(array $steps): array $configs[$name] = $builder->getStepConfig(); } - return FlowStepNode::fromConfig($configs); + return StepFlowNode::fromConfig($configs); } /** - * @return array + * @return array */ private static function buildBuilders(array $steps): array { $builders = []; foreach ($steps as $key => $value) { if (\is_int($key)) { - $builders[$value] = new FlowStepBuilder($value); + $builders[$value] = new StepFlowBuilder($value); } else { - $builder = new FlowStepBuilder($key); + $builder = new StepFlowBuilder($key); foreach (self::buildBuilders($value) as $child) { $builder->addStep($child); } @@ -256,11 +256,11 @@ public function testIsSkippedWithNullSkip() public function testGroupNodeIsSkipped() { - $stepA = (new FlowStepBuilder('stepA')) + $stepA = (new StepFlowBuilder('stepA')) ->setGroup(true) ->addStep('stepA1') ->addStep('stepA2'); - $roots = FlowStepNode::fromConfig(['stepA' => $stepA->getStepConfig()]); + $roots = StepFlowNode::fromConfig(['stepA' => $stepA->getStepConfig()]); $this->assertTrue($roots[0]->isGroup()); $this->assertTrue($roots[0]->isGroupOrSkipped(null)); @@ -271,11 +271,11 @@ public function testGroupNodeIsSkipped() public function testSkipPropagatesToChildren() { - $stepB = (new FlowStepBuilder('stepB')) + $stepB = (new StepFlowBuilder('stepB')) ->setSkip(fn () => true) ->addStep('stepB1') ->addStep('stepB2'); - $roots = FlowStepNode::fromConfig(['stepB' => $stepB->getStepConfig()]); + $roots = StepFlowNode::fromConfig(['stepB' => $stepB->getStepConfig()]); $this->assertTrue($roots[0]->isGroupOrSkipped(null)); $this->assertTrue($roots[0]->getChildren()[0]->isGroupOrSkipped(null)); @@ -284,13 +284,13 @@ public function testSkipPropagatesToChildren() public function testSkipPropagatesAcrossMultipleLevels() { - $stepA = (new FlowStepBuilder('stepA')) + $stepA = (new StepFlowBuilder('stepA')) ->setSkip(fn () => true) ->addStep( - (new FlowStepBuilder('stepA1')) + (new StepFlowBuilder('stepA1')) ->addStep('stepA11') ); - $roots = FlowStepNode::fromConfig(['stepA' => $stepA->getStepConfig()]); + $roots = StepFlowNode::fromConfig(['stepA' => $stepA->getStepConfig()]); $this->assertTrue($roots[0]->isGroupOrSkipped(null)); $stepA1 = $roots[0]->getChildren()[0]; @@ -300,14 +300,14 @@ public function testSkipPropagatesAcrossMultipleLevels() public function testSkipDoesNotPropagateWhenParentNotSkipped() { - $stepA = (new FlowStepBuilder('stepA')) + $stepA = (new StepFlowBuilder('stepA')) ->addStep( - (new FlowStepBuilder('stepA1')) + (new StepFlowBuilder('stepA1')) ->setSkip(fn () => true) ->addStep('stepA11') ) ->addStep('stepA2'); - $roots = FlowStepNode::fromConfig(['stepA' => $stepA->getStepConfig()]); + $roots = StepFlowNode::fromConfig(['stepA' => $stepA->getStepConfig()]); $this->assertFalse($roots[0]->isGroupOrSkipped(null)); @@ -320,13 +320,13 @@ public function testSkipDoesNotPropagateWhenParentNotSkipped() public function testGroupWithSkipOnChildrenAreSkipped() { - $stepA = (new FlowStepBuilder('stepA')) + $stepA = (new StepFlowBuilder('stepA')) ->setGroup(true) ->setSkip(fn () => true) ->addStep('stepA1') ->addStep('stepA2'); - $roots = FlowStepNode::fromConfig(['stepA' => $stepA->getStepConfig()]); + $roots = StepFlowNode::fromConfig(['stepA' => $stepA->getStepConfig()]); $this->assertTrue($roots[0]->isGroupOrSkipped(null)); $this->assertTrue($roots[0]->getChildren()[0]->isGroupOrSkipped(null)); @@ -335,13 +335,13 @@ public function testGroupWithSkipOnChildrenAreSkipped() public function testGroupWithNoChildrenThrows() { - $stepA = (new FlowStepBuilder('stepA')) + $stepA = (new StepFlowBuilder('stepA')) ->setGroup(true); $this->expectException(LogicException::class); $this->expectExceptionMessage('Step "stepA" is marked as group but has no child steps.'); - FlowStepNode::fromConfig(['stepA' => $stepA->getStepConfig()]); + StepFlowNode::fromConfig(['stepA' => $stepA->getStepConfig()]); } public function testMultipleForests() diff --git a/tests/Integration/App/FormFlowBasic/Form/Type/MultistepType.php b/tests/Integration/App/FormFlowBasic/Form/Type/MultistepType.php index 6c92948..527f26e 100644 --- a/tests/Integration/App/FormFlowBasic/Form/Type/MultistepType.php +++ b/tests/Integration/App/FormFlowBasic/Form/Type/MultistepType.php @@ -5,7 +5,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Yceruto\FormFlowBundle\Form\Flow\AbstractFlowType; use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNavigatorType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NavigatorFlowType; use Yceruto\FormFlowBundle\Tests\Integration\App\FormFlowBasic\Form\Data\MultistepDto; class MultistepType extends AbstractFlowType @@ -16,7 +16,7 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options) $builder->addStep('step2', Step2Type::class); $builder->addStep('step3', Step3Type::class); - $builder->add('navigator', FlowNavigatorType::class); + $builder->add('navigator', NavigatorFlowType::class); } public function configureOptions(OptionsResolver $resolver): void diff --git a/tests/Integration/App/FormFlowBasic/Form/Type/Step2Type.php b/tests/Integration/App/FormFlowBasic/Form/Type/Step2Type.php index c86f083..44e1847 100644 --- a/tests/Integration/App/FormFlowBasic/Form/Type/Step2Type.php +++ b/tests/Integration/App/FormFlowBasic/Form/Type/Step2Type.php @@ -5,7 +5,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Yceruto\FormFlowBundle\Form\Flow\Type\FlowNextType; +use Yceruto\FormFlowBundle\Form\Flow\Type\NextFlowType; use Yceruto\FormFlowBundle\Tests\Integration\App\FormFlowBasic\Form\Data\MultistepDto; class Step2Type extends AbstractType @@ -15,7 +15,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('field21'); $builder->add('field22'); - $builder->add('skip', FlowNextType::class, [ + $builder->add('skip', NextFlowType::class, [ 'clear_submission' => true, ]); }