diff --git a/src/StateConfigValidator.php b/src/StateConfigValidator.php index a7d6f4a..91fdb3f 100644 --- a/src/StateConfigValidator.php +++ b/src/StateConfigValidator.php @@ -309,7 +309,7 @@ private static function validateTransitionBehaviors( foreach ($behaviors as $behavior => $label) { if (isset($transitionConfig[$behavior])) { try { - $transitionConfig[$behavior] = self::normalizeArrayOrString($transitionConfig[$behavior]); + $transitionConfig[$behavior] = self::normalizeArrayOrString(value: $transitionConfig[$behavior]); } catch (InvalidArgumentException) { throw new InvalidArgumentException( message: "State '{$path}' has invalid {$behavior} configuration for event '{$eventName}'. ". diff --git a/tests/StateConfigValidatorTest.php b/tests/StateConfigValidatorTest.php index 082a24d..6ac52c4 100644 --- a/tests/StateConfigValidatorTest.php +++ b/tests/StateConfigValidatorTest.php @@ -117,6 +117,27 @@ exceptionMessage: "State 'state_a' has invalid condition in transition for event 'EVENT'. Each condition must be an array with target/guards/actions." ); }); + +test('validates guards configuration in transitions', function (): void { + expect(fn () => MachineDefinition::define([ + 'id' => 'machine', + 'initial' => 'state_a', + 'states' => [ + 'state_a' => [ + 'on' => [ + 'EVENT' => [ + 'target' => 'state_b', + 'guards' => true, // Guards should be an array or a string + ], + ], + ], + ], + ]))->toThrow( + InvalidArgumentException::class, + "State 'state_a' has invalid guards configuration for event 'EVENT'. Guards must be an array or string." + ); +}); + test('validates actions configuration in transitions', function (): void { expect(fn () => MachineDefinition::define([ 'id' => 'machine',