3 * Tests for IP validity functions.
5 * Ported from /t/inc/IP.t by avar.
7 * @todo Test methods in this call should be split into a method and a
13 * @covers AvroValidator
15 class AvroValidatorTest
extends MediaWikiUnitTestCase
{
17 public function setUp() {
18 if ( !class_exists( 'AvroSchema' ) ) {
19 $this->markTestSkipped( 'Avro is required to run the AvroValidatorTest' );
24 public function getErrorsProvider() {
25 $stringSchema = AvroSchema
::parse( json_encode( [ 'type' => 'string' ] ) );
26 $stringArraySchema = AvroSchema
::parse( json_encode( [
30 $recordSchema = AvroSchema
::parse( json_encode( [
34 [ 'name' => 'id', 'type' => 'int', 'required' => true ],
37 $enumSchema = AvroSchema
::parse( json_encode( [
41 [ 'name' => 'count', 'type' => [ 'int', 'null' ] ],
47 'No errors with a simple string serialization',
48 $stringSchema, 'foobar', [],
52 'Cannot serialize integer into string',
53 $stringSchema, 5, 'Expected string, but recieved integer',
57 'Cannot serialize array into string',
58 $stringSchema, [], 'Expected string, but recieved array',
62 'allows and ignores extra fields',
63 $recordSchema, [ 'id' => 4, 'foo' => 'bar' ], [],
67 'detects missing fields',
68 $recordSchema, [], [ 'id' => 'Missing expected field' ],
72 'handles first element in enum',
73 $enumSchema, [ 'count' => 4 ], [],
77 'handles second element in enum',
78 $enumSchema, [ 'count' => null ], [],
82 'rejects element not in union',
83 $enumSchema, [ 'count' => 'invalid' ], [ 'count' => [
84 'Expected any one of these to be true',
86 'Expected integer, but recieved string',
87 'Expected null, but recieved string',
92 'Empty array is accepted',
93 $stringArraySchema, [], []
96 'correct array element accepted',
97 $stringArraySchema, [ 'fizzbuzz' ], []
100 'incorrect array element rejected',
101 $stringArraySchema, [ '12', 34 ], [ 'Expected string, but recieved integer' ]
107 * @dataProvider getErrorsProvider
109 public function testGetErrors( $message, $schema, $datum, $expected ) {
112 AvroValidator
::getErrors( $schema, $datum ),