}
$errors = array();
foreach ($datum as $d) {
- $result = $this->validate( $schema->items(), $d );
+ $result = self::getErrors( $schema->items(), $d );
if ( $result ) {
$errors[] = $result;
}
}
- if ( $errors ) {
- return $errors;
- }
- return array();
+ return $errors;
case AvroSchema::MAP_SCHEMA:
if (!is_array($datum)) {
return self::wrongType( 'array', $datum );
}
$errors = array();
foreach ($datum as $k => $v) {
- if ( !is_string($k) ) {
+ if ( !is_string($k) ) {
$errors[] = self::wrongType( 'string key', $k );
}
$result = self::getErrors( $schema->values(), $v );
public function getErrorsProvider() {
$stringSchema = AvroSchema::parse( json_encode( array( 'type' => 'string' ) ) );
+ $stringArraySchema = AvroSchema::parse( json_encode( array(
+ 'type' => 'array',
+ 'items' => 'string',
+ ) ) );
$recordSchema = AvroSchema::parse( json_encode( array(
'type' => 'record',
'name' => 'ut',
)
) )
),
+ array(
+ 'Empty array is accepted',
+ $stringArraySchema, array(), array()
+ ),
+ array(
+ 'correct array element accepted',
+ $stringArraySchema, array( 'fizzbuzz' ), array()
+ ),
+ array(
+ 'incorrect array element rejected',
+ $stringArraySchema, array( '12', 34 ), array( 'Expected string, but recieved integer' )
+ ),
);
}