mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
✅ Make unit tests working
This commit is contained in:
@@ -195,12 +195,12 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
if (preg_match('/^\S+::\S+\(\): Argument #\d+ \(\$\S+\) must be of type (\S+), (\S+) given/', $message, $matches)) {
|
||||
[, $expectedType, $actualType] = $matches;
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
throw new InvalidArgumentException(\sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
}
|
||||
if (preg_match('/^Cannot assign (\S+) to property \S+::\$\S+ of type (\S+)$/', $message, $matches)) {
|
||||
[, $actualType, $expectedType] = $matches;
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
throw new InvalidArgumentException(\sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
];
|
||||
|
||||
// handle stdClass with properties with a dot in the name
|
||||
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
|
||||
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
|
||||
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
|
||||
} else {
|
||||
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
|
||||
@@ -308,13 +308,13 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
if (!$ignoreInvalidIndices && !$isNullSafe) {
|
||||
if (!\is_array($zval[self::VALUE])) {
|
||||
if (!$zval[self::VALUE] instanceof \Traversable) {
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s".', $property, (string) $propertyPath));
|
||||
throw new NoSuchIndexException(\sprintf('Cannot read index "%s" while trying to traverse path "%s".', $property, (string) $propertyPath));
|
||||
}
|
||||
|
||||
$zval[self::VALUE] = iterator_to_array($zval[self::VALUE]);
|
||||
}
|
||||
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".', $property, (string) $propertyPath, print_r(array_keys($zval[self::VALUE]), true)));
|
||||
throw new NoSuchIndexException(\sprintf('Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".', $property, (string) $propertyPath, print_r(array_keys($zval[self::VALUE]), true)));
|
||||
}
|
||||
|
||||
if ($i + 1 < $propertyPath->getLength()) {
|
||||
@@ -366,7 +366,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
private function readIndex(array $zval, string|int $index): array
|
||||
{
|
||||
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
|
||||
throw new NoSuchIndexException(\sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
|
||||
}
|
||||
|
||||
$result = self::RESULT_PROTO;
|
||||
@@ -394,7 +394,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
private function readProperty(array $zval, string $property, bool $ignoreInvalidProperty = false, bool $isNullSafe = false): array
|
||||
{
|
||||
if (!\is_object($zval[self::VALUE])) {
|
||||
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%1$s]" instead.', $property));
|
||||
throw new NoSuchPropertyException(\sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%1$s]" instead.', $property));
|
||||
}
|
||||
|
||||
$result = self::RESULT_PROTO;
|
||||
@@ -419,7 +419,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
&& $object instanceof $trace['class']
|
||||
&& preg_match('/Return value (?:of .*::\w+\(\) )?must be of (?:the )?type (\w+), null returned$/', $e->getMessage(), $matches)
|
||||
) {
|
||||
throw new UninitializedPropertyException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', get_debug_type($object), $name, $matches[1]), 0, $e);
|
||||
throw new UninitializedPropertyException(\sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', get_debug_type($object), $name, $matches[1]), 0, $e);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
@@ -430,11 +430,11 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
$r = new \ReflectionProperty($class, $name);
|
||||
|
||||
if ($r->isPublic() && !$r->hasType()) {
|
||||
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class, $name));
|
||||
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not initialized.', $class, $name));
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
if (!$ignoreInvalidProperty) {
|
||||
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
throw new NoSuchPropertyException(\sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -451,7 +451,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
$r = new \ReflectionProperty(str_contains($matches[1], '@anonymous') ? $class : $matches[1], $matches[2]);
|
||||
$type = ($type = $r->getType()) instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
|
||||
|
||||
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $matches[1], $r->getName(), $type), 0, $e);
|
||||
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $matches[1], $r->getName(), $type), 0, $e);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
@@ -464,7 +464,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
} elseif ($isNullSafe) {
|
||||
$result[self::VALUE] = null;
|
||||
} elseif (!$ignoreInvalidProperty) {
|
||||
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
throw new NoSuchPropertyException(\sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
}
|
||||
|
||||
// Objects are always passed around by reference
|
||||
@@ -514,7 +514,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
private function writeIndex(array $zval, string|int $index, mixed $value): void
|
||||
{
|
||||
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
|
||||
throw new NoSuchIndexException(sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
|
||||
throw new NoSuchIndexException(\sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
|
||||
}
|
||||
|
||||
$zval[self::REF][$index] = $value;
|
||||
@@ -528,7 +528,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
private function writeProperty(array $zval, string $property, mixed $value, bool $recursive = false): void
|
||||
{
|
||||
if (!\is_object($zval[self::VALUE])) {
|
||||
throw new NoSuchPropertyException(sprintf('Cannot write property "%s" to an array. Maybe you should write the property path as "[%1$s]" instead?', $property));
|
||||
throw new NoSuchPropertyException(\sprintf('Cannot write property "%s" to an array. Maybe you should write the property path as "[%1$s]" instead?', $property));
|
||||
}
|
||||
|
||||
$object = $zval[self::VALUE];
|
||||
@@ -553,7 +553,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
throw new NoSuchPropertyException(implode('. ', $mutator->getErrors()).'.');
|
||||
}
|
||||
|
||||
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s".', $property, get_debug_type($object)));
|
||||
throw new NoSuchPropertyException(\sprintf('Could not determine access type for property "%s" in class "%s".', $property, get_debug_type($object)));
|
||||
}
|
||||
} catch (\TypeError $e) {
|
||||
if ($recursive || !$value instanceof \DateTimeInterface || !\in_array($value::class, ['DateTime', 'DateTimeImmutable'], true) || __FILE__ !== ($e->getTrace()[0]['file'] ?? null)) {
|
||||
@@ -646,7 +646,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
|
||||
$mutatorForArray = $this->getWriteInfo($object::class, $property, []);
|
||||
if (PropertyWriteInfo::TYPE_PROPERTY === $mutatorForArray->getType()) {
|
||||
return $mutatorForArray->getVisibility() === 'public';
|
||||
return 'public' === $mutatorForArray->getVisibility();
|
||||
}
|
||||
|
||||
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType()) {
|
||||
@@ -696,7 +696,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
public static function createCache(string $namespace, int $defaultLifetime, string $version, ?LoggerInterface $logger = null): AdapterInterface
|
||||
{
|
||||
if (!class_exists(ApcuAdapter::class)) {
|
||||
throw new \LogicException(sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
|
||||
throw new \LogicException(\sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
|
||||
}
|
||||
|
||||
if (!ApcuAdapter::isSupported()) {
|
||||
|
||||
Reference in New Issue
Block a user