diff --git a/tests/CloneTest.php b/tests/CloneTest.php new file mode 100644 index 00000000..35b35fd0 --- /dev/null +++ b/tests/CloneTest.php @@ -0,0 +1,42 @@ +setValue('original'); + $clone = (clone $input) + ->setValue('clone'); + + $this->assertEquals('original', $this->getAttributeCallbackValue($input->getAttributes(), 'value')); + $this->assertEquals('clone', $this->getAttributeCallbackValue($clone->getAttributes(), 'value')); + } + + protected function getAttributeCallbackValue(Attributes $attributes, string $name) + { + $callbacksProperty = new ReflectionProperty(get_class($attributes), 'callbacks'); + $callbacksProperty->setAccessible(true); + $callbacks = $callbacksProperty->getValue($attributes); + + if (isset($callbacks[$name])) { + $attribute = $callbacks[$name](); + + if ($attribute instanceof Attribute) { + return $attribute->getValue(); + } + + return $attribute; + } + + throw new InvalidArgumentException(); + } +}