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( array( 'type' => 'string' ) ) );
22 $stringArraySchema = AvroSchema
::parse( json_encode( array(
26 $recordSchema = AvroSchema
::parse( json_encode( array(
30 array( 'name' => 'id', 'type' => 'int', 'required' => true ),
33 $enumSchema = AvroSchema
::parse( json_encode( array(
37 array( 'name' => 'count', 'type' => array( 'int', 'null' ) ),
43 'No errors with a simple string serialization',
44 $stringSchema, 'foobar', array(),
48 'Cannot serialize integer into string',
49 $stringSchema, 5, 'Expected string, but recieved integer',
53 'Cannot serialize array into string',
54 $stringSchema, array(), 'Expected string, but recieved array',
58 'allows and ignores extra fields',
59 $recordSchema, array( 'id' => 4, 'foo' => 'bar' ), array(),
63 'detects missing fields',
64 $recordSchema, array(), array( 'id' => 'Missing expected field' ),
68 'handles first element in enum',
69 $enumSchema, array( 'count' => 4 ), array(),
73 'handles second element in enum',
74 $enumSchema, array( 'count' => null ), array(),
78 'rejects element not in union',
79 $enumSchema, array( 'count' => 'invalid' ), array( 'count' => array(
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, array(), array()
92 'correct array element accepted',
93 $stringArraySchema, array( 'fizzbuzz' ), array()
96 'incorrect array element rejected',
97 $stringArraySchema, array( '12', 34 ), array( 'Expected string, but recieved integer' )
103 * @dataProvider getErrorsProvider
105 public function testGetErrors( $message, $schema, $datum, $expected ) {
108 AvroValidator
::getErrors( $schema, $datum ),