27 $stringSchema = AvroSchema::parse( json_encode( [
'type' =>
'string' ] ) );
28 $stringArraySchema = AvroSchema::parse( json_encode( [
32 $recordSchema = AvroSchema::parse( json_encode( [
36 [
'name' =>
'id',
'type' =>
'int',
'required' =>
true ],
39 $enumSchema = AvroSchema::parse( json_encode( [
43 [
'name' =>
'count',
'type' => [
'int',
'null' ] ],
49 'No errors with a simple string serialization',
50 $stringSchema,
'foobar', [],
54 'Cannot serialize integer into string',
55 $stringSchema, 5,
'Expected string, but recieved integer',
59 'Cannot serialize array into string',
60 $stringSchema, [],
'Expected string, but recieved array',
64 'allows and ignores extra fields',
65 $recordSchema, [
'id' => 4,
'foo' =>
'bar' ], [],
69 'detects missing fields',
70 $recordSchema, [], [
'id' =>
'Missing expected field' ],
74 'handles first element in enum',
75 $enumSchema, [
'count' => 4 ], [],
79 'handles second element in enum',
80 $enumSchema, [
'count' => null ], [],
84 'rejects element not in union',
85 $enumSchema, [
'count' =>
'invalid' ], [
'count' => [
86 'Expected any one of these to be true',
88 'Expected integer, but recieved string',
89 'Expected null, but recieved string',
94 'Empty array is accepted',
95 $stringArraySchema, [], []
98 'correct array element accepted',
99 $stringArraySchema, [
'fizzbuzz' ], []
102 'incorrect array element rejected',
103 $stringArraySchema, [
'12', 34 ], [
'Expected string, but recieved integer' ]