diff --git a/src/Validator/SchemaValidator.php b/src/Validator/SchemaValidator.php index da4d213..9f1d2b8 100644 --- a/src/Validator/SchemaValidator.php +++ b/src/Validator/SchemaValidator.php @@ -81,10 +81,16 @@ private function validateByAttributes(array $object, $schemaId, $attributes, arr if (!$attribute->isMultiValued()) { $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is not defined in schema as multi-valued, but got array'); continue; - } else { - foreach ($value as $item) { - $this->validateByAttributes($item, $schemaId, $attribute->getSubAttributes(), [], $validationResult, $propertyName); + } + foreach ($value as $item) { + if (!is_array($item)) { + if (!$attribute->isValueValid($item)) { + $validationResult->add($propertyName, $parentPath, $schemaId, sprintf('Attribute has invalid value for type "%s"', $attribute->getType())); + } + continue; } + + $this->validateByAttributes($item, $schemaId, $attribute->getSubAttributes(), [], $validationResult, $propertyName); } } elseif ($this->isObject($value)) { if ($attribute->isMultiValued()) { diff --git a/tests/Validator/SchemaValidatorTest.php b/tests/Validator/SchemaValidatorTest.php index edb6198..a771db7 100644 --- a/tests/Validator/SchemaValidatorTest.php +++ b/tests/Validator/SchemaValidatorTest.php @@ -44,6 +44,15 @@ public function test_full_user_representation() $this->assertEquals([], $result->getErrorsAsStrings()); } + public function test_list() + { + $schema = new Schema('customUser'); + $schema->addAttribute(AttributeBuilder::create('tags', ScimConstants::ATTRIBUTE_TYPE_STRING) + ->setMultiValued(true)->getAttribute(), + ); + $this->assertEmpty($this->validator->validate(['tags' => ['foo']], $schema)->getErrors()); + } + public function test_enterprise_user_full() { $result = $this->validator->validate(