From 2b59e3df4985f54d76c264088d87df691ef08135 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Mon, 29 Jan 2024 20:31:56 +0100 Subject: [PATCH] Only pass the necessary parameters to the exceptions Currently, we convert the properties of a rule into parameters and pass them to the exceptions. That complicates things for a few reasons: 1. The exception knows too much: there's a lot of information in an object, and the exception would only need a few parameters to work correctly. 2. Any variable change becomes a backward compatibility break: if we change the name of the variable type in a rule, even if it's a private one, we may need to change the template, which is a backward compatibility break. 3. The factory is bloated because of introspection tricks: it reads the properties from the class, even from the parent, and then passes it to the exception. Of course, that means we introduce another method to `Validatable`, but in most cases, extending `AbstractRule` is enough to create a new rule. Signed-off-by: Henrique Moody --- library/Factory.php | 30 +--------------------------- library/Rules/AbstractAge.php | 8 ++++++++ library/Rules/AbstractComparison.php | 8 ++++++++ library/Rules/AbstractFilterRule.php | 8 ++++++++ library/Rules/AbstractRule.php | 8 ++++++++ library/Rules/Base.php | 8 ++++++++ library/Rules/Call.php | 8 ++++++++ library/Rules/Charset.php | 8 ++++++++ library/Rules/Contains.php | 8 ++++++++ library/Rules/CreditCard.php | 8 ++++++++ library/Rules/Date.php | 12 +++++++---- library/Rules/DateTime.php | 11 +++++++--- library/Rules/Decimal.php | 8 ++++++++ library/Rules/EndsWith.php | 8 ++++++++ library/Rules/Equals.php | 11 +++------- library/Rules/Equivalent.php | 8 ++++++++ library/Rules/Extension.php | 8 ++++++++ library/Rules/Factor.php | 8 ++++++++ library/Rules/Identical.php | 11 +++------- library/Rules/In.php | 8 ++++++++ library/Rules/Instance.php | 8 ++++++++ library/Rules/Ip.php | 8 ++++++++ library/Rules/KeySet.php | 11 ++++++++++ library/Rules/KeyValue.php | 11 ++++++++++ library/Rules/Length.php | 11 ++++++++++ library/Rules/Mimetype.php | 8 ++++++++ library/Rules/Multiple.php | 8 ++++++++ library/Rules/Phone.php | 8 ++++++++ library/Rules/Regex.php | 8 ++++++++ library/Rules/Size.php | 15 ++++++++++++-- library/Rules/StartsWith.php | 8 ++++++++ library/Rules/SubdivisionCode.php | 8 ++++++++ library/Rules/Subset.php | 8 ++++++++ library/Rules/Time.php | 12 +++++++---- library/Rules/Type.php | 8 ++++++++ library/Rules/Uuid.php | 8 ++++++++ library/Rules/VideoUrl.php | 8 ++++++++ library/Validatable.php | 5 +++++ phpstan.neon.dist | 4 ---- tests/unit/FactoryTest.php | 14 ------------- tests/unit/Rules/DateTest.php | 10 ---------- tests/unit/Rules/DateTimeTest.php | 10 ---------- tests/unit/Rules/TimeTest.php | 10 ---------- 43 files changed, 298 insertions(+), 106 deletions(-) diff --git a/library/Factory.php b/library/Factory.php index bdf76225f..b2ee5e044 100644 --- a/library/Factory.php +++ b/library/Factory.php @@ -128,7 +128,7 @@ public function exception(Validatable $validatable, mixed $input, array $extraPa $formatter = new Formatter($this->translator, $this->parameterStringifier); $reflection = new ReflectionObject($validatable); $ruleName = $reflection->getShortName(); - $params = ['input' => $input] + $extraParams + $this->extractPropertiesValues($validatable, $reflection); + $params = ['input' => $input] + $extraParams + $validatable->getParams(); $id = lcfirst($ruleName); if ($validatable->getName() !== null) { $id = $params['name'] = $validatable->getName(); @@ -181,32 +181,4 @@ private function createReflectionClass(string $name, string $parentName): Reflec return $reflection; } - - /** - * @param ReflectionObject|ReflectionClass $reflection - * @return mixed[] - */ - private function extractPropertiesValues(Validatable $validatable, ReflectionClass $reflection): array - { - $values = []; - foreach ($reflection->getProperties() as $property) { - if (!$property->isInitialized($validatable)) { - continue; - } - - $propertyValue = $property->getValue($validatable); - if ($propertyValue === null) { - continue; - } - - $values[$property->getName()] = $propertyValue; - } - - $parentReflection = $reflection->getParentClass(); - if ($parentReflection !== false) { - return $values + $this->extractPropertiesValues($validatable, $parentReflection); - } - - return $values; - } } diff --git a/library/Rules/AbstractAge.php b/library/Rules/AbstractAge.php index 66bb25d72..0e43ba380 100644 --- a/library/Rules/AbstractAge.php +++ b/library/Rules/AbstractAge.php @@ -45,6 +45,14 @@ public function validate(mixed $input): bool return $this->isValidWithFormat($this->format, (string) $input); } + /** + * @return array + */ + public function getParams(): array + { + return ['age' => $this->age]; + } + private function isValidWithoutFormat(string $dateTime): bool { $timestamp = strtotime($dateTime); diff --git a/library/Rules/AbstractComparison.php b/library/Rules/AbstractComparison.php index 17e6c88bf..29e9112d6 100644 --- a/library/Rules/AbstractComparison.php +++ b/library/Rules/AbstractComparison.php @@ -35,4 +35,12 @@ public function validate(mixed $input): bool return $this->compare($left, $right); } + + /** + * @return array + */ + public function getParams(): array + { + return ['compareTo' => $this->compareTo]; + } } diff --git a/library/Rules/AbstractFilterRule.php b/library/Rules/AbstractFilterRule.php index 6630a7be0..60806e410 100644 --- a/library/Rules/AbstractFilterRule.php +++ b/library/Rules/AbstractFilterRule.php @@ -48,6 +48,14 @@ public function getTemplate(mixed $input): string return $this->template ?? ($this->additionalChars ? self::TEMPLATE_EXTRA : self::TEMPLATE_STANDARD); } + /** + * @return array + */ + public function getParams(): array + { + return ['additionalChars' => $this->additionalChars]; + } + private function filter(string $input): string { return str_replace(str_split($this->additionalChars), '', $input); diff --git a/library/Rules/AbstractRule.php b/library/Rules/AbstractRule.php index 736e3c711..0c65466ce 100644 --- a/library/Rules/AbstractRule.php +++ b/library/Rules/AbstractRule.php @@ -65,6 +65,14 @@ public function getTemplate(mixed $input): string return $this->template ?? self::TEMPLATE_STANDARD; } + /** + * @return array + */ + public function getParams(): array + { + return []; + } + public function __invoke(mixed $input): bool { return $this->validate($input); diff --git a/library/Rules/Base.php b/library/Rules/Base.php index 43f8536ee..369e7a692 100644 --- a/library/Rules/Base.php +++ b/library/Rules/Base.php @@ -34,4 +34,12 @@ public function validate(mixed $input): bool return (bool) preg_match('@^[' . $valid . ']+$@', (string) $input); } + + /** + * @return array + */ + public function getParams(): array + { + return ['base' => $this->base]; + } } diff --git a/library/Rules/Call.php b/library/Rules/Call.php index 2b4d67e87..8c775e134 100644 --- a/library/Rules/Call.php +++ b/library/Rules/Call.php @@ -72,6 +72,14 @@ public function validate(mixed $input): bool return true; } + /** + * @return array + */ + public function getParams(): array + { + return ['callable' => $this->callable]; + } + private function setErrorHandler(mixed $input): void { set_error_handler(function () use ($input): void { diff --git a/library/Rules/Charset.php b/library/Rules/Charset.php index 0bc29a46e..cc63b9030 100644 --- a/library/Rules/Charset.php +++ b/library/Rules/Charset.php @@ -40,4 +40,12 @@ public function validate(mixed $input): bool { return in_array(mb_detect_encoding($input, $this->charset, true), $this->charset, true); } + + /** + * @return array> + */ + public function getParams(): array + { + return ['charset' => $this->charset]; + } } diff --git a/library/Rules/Contains.php b/library/Rules/Contains.php index eb2b79a81..642532e98 100644 --- a/library/Rules/Contains.php +++ b/library/Rules/Contains.php @@ -36,6 +36,14 @@ public function validate(mixed $input): bool return $this->validateString((string) $input, (string) $this->containsValue); } + /** + * @return array + */ + public function getParams(): array + { + return ['containsValue' => $this->containsValue]; + } + private function validateString(string $haystack, string $needle): bool { if ($needle === '') { diff --git a/library/Rules/CreditCard.php b/library/Rules/CreditCard.php index 11501877e..76d16d050 100644 --- a/library/Rules/CreditCard.php +++ b/library/Rules/CreditCard.php @@ -92,4 +92,12 @@ public function getTemplate(mixed $input): string return self::TEMPLATE_BRANDED; } + + /** + * @return array + */ + public function getParams(): array + { + return ['brand' => $this->brand]; + } } diff --git a/library/Rules/Date.php b/library/Rules/Date.php index 1a4b182f5..c717ecd2b 100644 --- a/library/Rules/Date.php +++ b/library/Rules/Date.php @@ -22,8 +22,6 @@ final class Date extends AbstractRule { use CanValidateDateTime; - private readonly string $sample; - /** * @throws ComponentException */ @@ -33,8 +31,6 @@ public function __construct( if (!preg_match('/^[djSFmMnYy\W]+$/', $format)) { throw new ComponentException(sprintf('"%s" is not a valid date format', $format)); } - - $this->sample = date($format, strtotime('2005-12-30')); } public function validate(mixed $input): bool @@ -45,4 +41,12 @@ public function validate(mixed $input): bool return $this->isDateTime($this->format, (string) $input); } + + /** + * @return array + */ + public function getParams(): array + { + return ['sample' => date($this->format, strtotime('2005-12-30'))]; + } } diff --git a/library/Rules/DateTime.php b/library/Rules/DateTime.php index c455c3eb4..20d6cc1fb 100644 --- a/library/Rules/DateTime.php +++ b/library/Rules/DateTime.php @@ -22,12 +22,9 @@ final class DateTime extends AbstractRule public const TEMPLATE_FORMAT = 'format'; - private readonly string $sample; - public function __construct( private readonly ?string $format = null ) { - $this->sample = date($format ?: 'c', strtotime('2005-12-30 01:02:03')); } public function validate(mixed $input): bool @@ -51,4 +48,12 @@ public function getTemplate(mixed $input): string { return $this->template ?? ($this->format !== null ? self::TEMPLATE_FORMAT : self::TEMPLATE_STANDARD); } + + /** + * @return array + */ + public function getParams(): array + { + return ['sample' => date($this->format ?: 'c', strtotime('2005-12-30 01:02:03'))]; + } } diff --git a/library/Rules/Decimal.php b/library/Rules/Decimal.php index f688f5d82..b947703d9 100644 --- a/library/Rules/Decimal.php +++ b/library/Rules/Decimal.php @@ -31,6 +31,14 @@ public function validate(mixed $input): bool return $this->toFormattedString($input) === $this->toRawString($input); } + /** + * @return array + */ + public function getParams(): array + { + return ['decimals' => $this->decimals]; + } + private function toRawString(mixed $input): string { if (is_string($input)) { diff --git a/library/Rules/EndsWith.php b/library/Rules/EndsWith.php index e6f8493b2..29dc3ca0f 100644 --- a/library/Rules/EndsWith.php +++ b/library/Rules/EndsWith.php @@ -32,6 +32,14 @@ public function validate(mixed $input): bool return $this->validateEquals($input); } + /** + * @return array + */ + public function getParams(): array + { + return ['endValue' => $this->endValue]; + } + private function validateEquals(mixed $input): bool { if (is_array($input)) { diff --git a/library/Rules/Equals.php b/library/Rules/Equals.php index acdffb98f..bcd3e773c 100644 --- a/library/Rules/Equals.php +++ b/library/Rules/Equals.php @@ -9,15 +9,10 @@ namespace Respect\Validation\Rules; -final class Equals extends AbstractRule +final class Equals extends AbstractComparison { - public function __construct( - private readonly mixed $compareTo - ) { - } - - public function validate(mixed $input): bool + protected function compare(mixed $left, mixed $right): bool { - return $input == $this->compareTo; + return $left == $right; } } diff --git a/library/Rules/Equivalent.php b/library/Rules/Equivalent.php index d44aafe27..444c07700 100644 --- a/library/Rules/Equivalent.php +++ b/library/Rules/Equivalent.php @@ -28,6 +28,14 @@ public function validate(mixed $input): bool return $input == $this->compareTo; } + /** + * @return array + */ + public function getParams(): array + { + return ['compareTo' => $this->compareTo]; + } + private function isStringEquivalent(string $input): bool { if (!is_scalar($this->compareTo)) { diff --git a/library/Rules/Extension.php b/library/Rules/Extension.php index dba62f24c..ad41aa56d 100644 --- a/library/Rules/Extension.php +++ b/library/Rules/Extension.php @@ -35,4 +35,12 @@ public function validate(mixed $input): bool return $this->extension === pathinfo($input, PATHINFO_EXTENSION); } + + /** + * @return array + */ + public function getParams(): array + { + return ['extension' => $this->extension]; + } } diff --git a/library/Rules/Factor.php b/library/Rules/Factor.php index b59bfaf50..718f3522d 100644 --- a/library/Rules/Factor.php +++ b/library/Rules/Factor.php @@ -40,4 +40,12 @@ public function validate(mixed $input): bool // factor of the dividend. return is_integer($dividend / $input); } + + /** + * @return array + */ + public function getParams(): array + { + return ['dividend' => $this->dividend]; + } } diff --git a/library/Rules/Identical.php b/library/Rules/Identical.php index f5bfab30e..cf68be869 100644 --- a/library/Rules/Identical.php +++ b/library/Rules/Identical.php @@ -9,15 +9,10 @@ namespace Respect\Validation\Rules; -final class Identical extends AbstractRule +final class Identical extends AbstractComparison { - public function __construct( - private readonly mixed $compareTo - ) { - } - - public function validate(mixed $input): bool + protected function compare(mixed $left, mixed $right): bool { - return $input === $this->compareTo; + return $left === $right; } } diff --git a/library/Rules/In.php b/library/Rules/In.php index 1de0edb04..88912c222 100644 --- a/library/Rules/In.php +++ b/library/Rules/In.php @@ -31,6 +31,14 @@ public function validate(mixed $input): bool return $this->validateEquals($input); } + /** + * @return array + */ + public function getParams(): array + { + return ['haystack' => $this->haystack]; + } + private function validateEquals(mixed $input): bool { if (is_array($this->haystack)) { diff --git a/library/Rules/Instance.php b/library/Rules/Instance.php index f49bda8f7..15ab17d70 100644 --- a/library/Rules/Instance.php +++ b/library/Rules/Instance.php @@ -20,4 +20,12 @@ public function validate(mixed $input): bool { return $input instanceof $this->instanceName; } + + /** + * @return array + */ + public function getParams(): array + { + return ['instanceName' => $this->instanceName]; + } } diff --git a/library/Rules/Ip.php b/library/Rules/Ip.php index 36c20563f..072e30f15 100644 --- a/library/Rules/Ip.php +++ b/library/Rules/Ip.php @@ -73,6 +73,14 @@ public function getTemplate(mixed $input): string return $this->template ?? ($this->range ? self::TEMPLATE_NETWORK_RANGE : self::TEMPLATE_STANDARD); } + /** + * @return array + */ + public function getParams(): array + { + return ['range' => $this->range]; + } + private function createRange(): ?string { if ($this->startAddress && $this->endAddress) { diff --git a/library/Rules/KeySet.php b/library/Rules/KeySet.php index 1b4a7e6e6..582deb454 100644 --- a/library/Rules/KeySet.php +++ b/library/Rules/KeySet.php @@ -89,6 +89,17 @@ public function getTemplate(mixed $input): string return KeySet::TEMPLATE_STRUCTURE; } + /** + * @return array + */ + public function getParams(): array + { + return [ + 'keys' => $this->keys, + 'extraKeys' => $this->extraKeys, + ]; + } + /** * @throws ComponentException */ diff --git a/library/Rules/KeyValue.php b/library/Rules/KeyValue.php index cd9e0a3cc..4812b58e5 100644 --- a/library/Rules/KeyValue.php +++ b/library/Rules/KeyValue.php @@ -81,6 +81,17 @@ public function getTemplate(mixed $input): string return self::TEMPLATE_STANDARD; } + /** + * @return array + */ + public function getParams(): array + { + return [ + 'baseKey' => $this->baseKey, + 'comparedKey' => $this->comparedKey, + ]; + } + /** * @param mixed[] $extraParameters */ diff --git a/library/Rules/Length.php b/library/Rules/Length.php index 123e1f044..dfa5d01f2 100644 --- a/library/Rules/Length.php +++ b/library/Rules/Length.php @@ -75,6 +75,17 @@ public function getTemplate(mixed $input): string return self::TEMPLATE_BOTH; } + /** + * @return array + */ + public function getParams(): array + { + return [ + 'minValue' => $this->minValue, + 'maxValue' => $this->maxValue, + ]; + } + private function extractLength(mixed $input): ?int { if (is_string($input)) { diff --git a/library/Rules/Mimetype.php b/library/Rules/Mimetype.php index 8e50be3bb..43d5980b8 100644 --- a/library/Rules/Mimetype.php +++ b/library/Rules/Mimetype.php @@ -41,4 +41,12 @@ public function validate(mixed $input): bool return $this->mimetype === $this->fileInfo->file($input, FILEINFO_MIME_TYPE); } + + /** + * @return array + */ + public function getParams(): array + { + return ['mimetype' => $this->mimetype]; + } } diff --git a/library/Rules/Multiple.php b/library/Rules/Multiple.php index ce3340135..eaaaf9313 100644 --- a/library/Rules/Multiple.php +++ b/library/Rules/Multiple.php @@ -24,4 +24,12 @@ public function validate(mixed $input): bool return $input % $this->multipleOf == 0; } + + /** + * @return array + */ + public function getParams(): array + { + return ['multipleOf' => $this->multipleOf]; + } } diff --git a/library/Rules/Phone.php b/library/Rules/Phone.php index 41f5b7b0f..4f880a2a9 100644 --- a/library/Rules/Phone.php +++ b/library/Rules/Phone.php @@ -63,4 +63,12 @@ public function getTemplate(mixed $input): string { return $this->template ?? $this->countryName ? self::TEMPLATE_FOR_COUNTRY : self::TEMPLATE_INTERNATIONAL; } + + /** + * @return array + */ + public function getParams(): array + { + return ['countryName' => $this->countryName]; + } } diff --git a/library/Rules/Regex.php b/library/Rules/Regex.php index 7986e2833..6abe7d980 100644 --- a/library/Rules/Regex.php +++ b/library/Rules/Regex.php @@ -27,4 +27,12 @@ public function validate(mixed $input): bool return preg_match($this->regex, (string) $input) > 0; } + + /** + * @return array + */ + public function getParams(): array + { + return ['regex' => $this->regex]; + } } diff --git a/library/Rules/Size.php b/library/Rules/Size.php index 7c018e233..52146473e 100644 --- a/library/Rules/Size.php +++ b/library/Rules/Size.php @@ -32,8 +32,8 @@ final class Size extends AbstractRule private readonly ?float $maxValue; public function __construct( - private string|int|null $minSize = null, - private string|int|null $maxSize = null + private readonly string|int|null $minSize = null, + private readonly string|int|null $maxSize = null ) { $this->minValue = $minSize ? $this->toBytes((string) $minSize) : null; $this->maxValue = $maxSize ? $this->toBytes((string) $maxSize) : null; @@ -77,6 +77,17 @@ public function getTemplate(mixed $input): string return self::TEMPLATE_BOTH; } + /** + * @return array + */ + public function getParams(): array + { + return [ + 'minSize' => $this->minSize, + 'maxSize' => $this->maxSize, + ]; + } + /** * @todo Move it to a trait */ diff --git a/library/Rules/StartsWith.php b/library/Rules/StartsWith.php index 4d29cd0b7..c97e8baca 100644 --- a/library/Rules/StartsWith.php +++ b/library/Rules/StartsWith.php @@ -32,6 +32,14 @@ public function validate(mixed $input): bool return $this->validateEquals($input); } + /** + * @return array + */ + public function getParams(): array + { + return ['startValue' => $this->startValue]; + } + protected function validateEquals(mixed $input): bool { if (is_array($input)) { diff --git a/library/Rules/SubdivisionCode.php b/library/Rules/SubdivisionCode.php index 6b50a15e2..a700ab260 100644 --- a/library/Rules/SubdivisionCode.php +++ b/library/Rules/SubdivisionCode.php @@ -34,6 +34,14 @@ public function __construct(string $countryCode) $this->countryInfo = array_keys($countryInfo->getSubdivisions()); } + /** + * @return array + */ + public function getParams(): array + { + return ['countryName' => $this->countryName]; + } + /** * @return array */ diff --git a/library/Rules/Subset.php b/library/Rules/Subset.php index ab52be4fa..5ce33b3a7 100644 --- a/library/Rules/Subset.php +++ b/library/Rules/Subset.php @@ -30,4 +30,12 @@ public function validate(mixed $input): bool return array_diff($input, $this->superset) === []; } + + /** + * @return array + */ + public function getParams(): array + { + return ['superset' => $this->superset]; + } } diff --git a/library/Rules/Time.php b/library/Rules/Time.php index 91bf03e72..0a04d4054 100644 --- a/library/Rules/Time.php +++ b/library/Rules/Time.php @@ -22,8 +22,6 @@ final class Time extends AbstractRule { use CanValidateDateTime; - private readonly string $sample; - /** * @throws ComponentException */ @@ -33,8 +31,6 @@ public function __construct( if (!preg_match('/^[gGhHisuvaA\W]+$/', $format)) { throw new ComponentException(sprintf('"%s" is not a valid date format', $format)); } - - $this->sample = date($format, strtotime('23:59:59')); } public function validate(mixed $input): bool @@ -45,4 +41,12 @@ public function validate(mixed $input): bool return $this->isDateTime($this->format, (string) $input); } + + /** + * @return array + */ + public function getParams(): array + { + return ['sample' => date($this->format, strtotime('23:59:59'))]; + } } diff --git a/library/Rules/Type.php b/library/Rules/Type.php index fd39597ef..ece805257 100644 --- a/library/Rules/Type.php +++ b/library/Rules/Type.php @@ -59,4 +59,12 @@ public function validate(mixed $input): bool return self::AVAILABLE_TYPES[$this->type] === gettype($input); } + + /** + * @return array + */ + public function getParams(): array + { + return ['type' => $this->type]; + } } diff --git a/library/Rules/Uuid.php b/library/Rules/Uuid.php index e87f90d17..f52c21475 100644 --- a/library/Rules/Uuid.php +++ b/library/Rules/Uuid.php @@ -46,6 +46,14 @@ public function getTemplate(mixed $input): string return $this->template ?? ($this->version ? self::TEMPLATE_VERSION : self::TEMPLATE_STANDARD); } + /** + * @return array + */ + public function getParams(): array + { + return ['version' => $this->version]; + } + private function isSupportedVersion(int $version): bool { return $version >= 1 && $version <= 5 && $version !== 2; diff --git a/library/Rules/VideoUrl.php b/library/Rules/VideoUrl.php index 3d8a6adfd..07793be85 100644 --- a/library/Rules/VideoUrl.php +++ b/library/Rules/VideoUrl.php @@ -66,6 +66,14 @@ public function getTemplate(mixed $input): string return $this->template ?? ($this->service ? self::TEMPLATE_SERVICE : self::TEMPLATE_STANDARD); } + /** + * @return array + */ + public function getParams(): array + { + return ['service' => $this->service]; + } + private function isSupportedService(string $service): bool { return isset(self::SERVICES[mb_strtolower($service)]); diff --git a/library/Validatable.php b/library/Validatable.php index b6875297b..5ec4442c9 100644 --- a/library/Validatable.php +++ b/library/Validatable.php @@ -32,5 +32,10 @@ public function setTemplate(string $template): Validatable; public function getTemplate(mixed $input): string; + /** + * @return array + */ + public function getParams(): array; + public function validate(mixed $input): bool; } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1fc2e5c1d..1450f20e1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,10 +7,6 @@ parameters: - php - phpt ignoreErrors: - - - # Why: Properties are read dynamically during message construction - message: '/Property Respect\\Validation\\Rules\\[a-zA-Z0-9\\_]+::\$[a-zA-Z0-9\\_]+ is never read, only written\./' - - # Why: SimpleXMLElement is weird and doesn't implement anything ArrayAccess-like message: '/Instanceof between mixed and SimpleXMLElement will always evaluate to false\./' diff --git a/tests/unit/FactoryTest.php b/tests/unit/FactoryTest.php index d701fc1d3..3d2f1c6a2 100644 --- a/tests/unit/FactoryTest.php +++ b/tests/unit/FactoryTest.php @@ -143,20 +143,6 @@ public function shouldSetInputAsParameterOfCreatedException(): void self::assertSame($input, $exception->getParam('input')); } - #[Test] - public function shouldPassPropertiesToCreatedException(): void - { - $factory = (new Factory())->withExceptionNamespace(self::TEST_EXCEPTIONS_NAMESPACE); - - $validations = [true, false, true, true]; - $rule = new Stub(...$validations); - $input = 2; - - $exception = $factory->exception($rule, $input); - - self::assertSame($validations, $exception->getParam('validations')); - } - #[Test] public function shouldSetTemplateWhenTemplateKeyIsDefined(): void { diff --git a/tests/unit/Rules/DateTest.php b/tests/unit/Rules/DateTest.php index f035190a8..f009b11c6 100644 --- a/tests/unit/Rules/DateTest.php +++ b/tests/unit/Rules/DateTest.php @@ -31,16 +31,6 @@ public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void new Date($format); } - #[Test] - public function shouldPassFormatToParameterToException(): void - { - $format = 'F jS, Y'; - $equals = new Date($format); - $exception = $equals->reportError('input'); - - self::assertSame($format, $exception->getParam('format')); - } - /** * @return string[][] */ diff --git a/tests/unit/Rules/DateTimeTest.php b/tests/unit/Rules/DateTimeTest.php index 646ebf160..0211926f7 100644 --- a/tests/unit/Rules/DateTimeTest.php +++ b/tests/unit/Rules/DateTimeTest.php @@ -24,16 +24,6 @@ #[CoversClass(DateTime::class)] final class DateTimeTest extends RuleTestCase { - #[Test] - public function shouldPassFormatToParameterToException(): void - { - $format = 'F jS, Y'; - $equals = new DateTime($format); - $exception = $equals->reportError('input'); - - self::assertSame($format, $exception->getParam('format')); - } - #[Test] #[DataProvider('providerForDateTimeWithTimezone')] public function shouldValidateNoMatterTimezone(string $format, string $input, string $timezone): void diff --git a/tests/unit/Rules/TimeTest.php b/tests/unit/Rules/TimeTest.php index 878dbdf87..4ebe58668 100644 --- a/tests/unit/Rules/TimeTest.php +++ b/tests/unit/Rules/TimeTest.php @@ -31,16 +31,6 @@ public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void new Time($format); } - #[Test] - public function shouldPassFormatToParameterToException(): void - { - $format = 'g:i A'; - $equals = new Time($format); - $exception = $equals->reportError('input'); - - self::assertSame($format, $exception->getParam('format')); - } - /** * @return mixed[][] */