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 $recordSchema = AvroSchema
::parse( json_encode( array(
26 array( 'name' => 'id', 'type' => 'int', 'required' => true ),
29 $enumSchema = AvroSchema
::parse( json_encode( array(
33 array( 'name' => 'count', 'type' => array( 'int', 'null' ) ),
39 'No errors with a simple string serialization',
40 $stringSchema, 'foobar', array(),
44 'Cannot serialize integer into string',
45 $stringSchema, 5, 'Expected string, but recieved integer',
49 'Cannot serialize array into string',
50 $stringSchema, array(), 'Expected string, but recieved array',
54 'allows and ignores extra fields',
55 $recordSchema, array( 'id' => 4, 'foo' => 'bar' ), array(),
59 'detects missing fields',
60 $recordSchema, array(), array( 'id' => 'Missing expected field' ),
64 'handles first element in enum',
65 $enumSchema, array( 'count' => 4 ), array(),
69 'handles second element in enum',
70 $enumSchema, array( 'count' => null ), array(),
74 'rejects element not in union',
75 $enumSchema, array( 'count' => 'invalid' ), array( 'count' => array(
76 'Expected any one of these to be true',
78 'Expected integer, but recieved string',
79 'Expected null, but recieved string',
87 * @dataProvider getErrorsProvider
89 public function testGetErrors( $message, $schema, $datum, $expected ) {
92 AvroValidator
::getErrors( $schema, $datum ),