3 * Tests for IP validity functions.
5 * Ported from /t/inc/IP.t by avar.
8 * @todo Test methods in this call should be split into a method and a
12 class AvroValidatorTest
extends PHPUnit_Framework_TestCase
{
13 public function setUp() {
14 if ( !class_exists( 'AvroSchema' ) ) {
15 $this->markTestSkipped( 'Avro is required to run the AvroValidatorTest' );
20 public function getErrorsProvider() {
21 $stringSchema = AvroSchema
::parse( json_encode( [ 'type' => 'string' ] ) );
22 $stringArraySchema = AvroSchema
::parse( json_encode( [
26 $recordSchema = AvroSchema
::parse( json_encode( [
30 [ 'name' => 'id', 'type' => 'int', 'required' => true ],
33 $enumSchema = AvroSchema
::parse( json_encode( [
37 [ 'name' => 'count', 'type' => [ 'int', 'null' ] ],
43 'No errors with a simple string serialization',
44 $stringSchema, 'foobar', [],
48 'Cannot serialize integer into string',
49 $stringSchema, 5, 'Expected string, but recieved integer',
53 'Cannot serialize array into string',
54 $stringSchema, [], 'Expected string, but recieved array',
58 'allows and ignores extra fields',
59 $recordSchema, [ 'id' => 4, 'foo' => 'bar' ], [],
63 'detects missing fields',
64 $recordSchema, [], [ 'id' => 'Missing expected field' ],
68 'handles first element in enum',
69 $enumSchema, [ 'count' => 4 ], [],
73 'handles second element in enum',
74 $enumSchema, [ 'count' => null ], [],
78 'rejects element not in union',
79 $enumSchema, [ 'count' => 'invalid' ], [ 'count' => [
80 'Expected any one of these to be true',
82 'Expected integer, but recieved string',
83 'Expected null, but recieved string',
88 'Empty array is accepted',
89 $stringArraySchema, [], []
92 'correct array element accepted',
93 $stringArraySchema, [ 'fizzbuzz' ], []
96 'incorrect array element rejected',
97 $stringArraySchema, [ '12', 34 ], [ 'Expected string, but recieved integer' ]
103 * @dataProvider getErrorsProvider
105 public function testGetErrors( $message, $schema, $datum, $expected ) {
108 AvroValidator
::getErrors( $schema, $datum ),