From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- tests/phpunit/includes/utils/AvroValidatorTest.php | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/phpunit/includes/utils/AvroValidatorTest.php (limited to 'tests/phpunit/includes/utils/AvroValidatorTest.php') diff --git a/tests/phpunit/includes/utils/AvroValidatorTest.php b/tests/phpunit/includes/utils/AvroValidatorTest.php new file mode 100644 index 00000000..52c242c1 --- /dev/null +++ b/tests/phpunit/includes/utils/AvroValidatorTest.php @@ -0,0 +1,96 @@ +markTestSkipped( 'Avro is required to run the AvroValidatorTest' ); + } + parent::setUp(); + } + + public function getErrorsProvider() { + $stringSchema = AvroSchema::parse( json_encode( array( 'type' => 'string' ) ) ); + $recordSchema = AvroSchema::parse( json_encode( array( + 'type' => 'record', + 'name' => 'ut', + 'fields' => array( + array( 'name' => 'id', 'type' => 'int', 'required' => true ), + ), + ) ) ); + $enumSchema = AvroSchema::parse( json_encode( array( + 'type' => 'record', + 'name' => 'ut', + 'fields' => array( + array( 'name' => 'count', 'type' => array( 'int', 'null' ) ), + ), + ) ) ); + + return array( + array( + 'No errors with a simple string serialization', + $stringSchema, 'foobar', array(), + ), + + array( + 'Cannot serialize integer into string', + $stringSchema, 5, 'Expected string, but recieved integer', + ), + + array( + 'Cannot serialize array into string', + $stringSchema, array(), 'Expected string, but recieved array', + ), + + array( + 'allows and ignores extra fields', + $recordSchema, array( 'id' => 4, 'foo' => 'bar' ), array(), + ), + + array( + 'detects missing fields', + $recordSchema, array(), array( 'id' => 'Missing expected field' ), + ), + + array( + 'handles first element in enum', + $enumSchema, array( 'count' => 4 ), array(), + ), + + array( + 'handles second element in enum', + $enumSchema, array( 'count' => null ), array(), + ), + + array( + 'rejects element not in union', + $enumSchema, array( 'count' => 'invalid' ), array( 'count' => array( + 'Expected any one of these to be true', + array( + 'Expected integer, but recieved string', + 'Expected null, but recieved string', + ) + ) ) + ), + ); + } + + /** + * @dataProvider getErrorsProvider + */ + public function testGetErrors( $message, $schema, $datum, $expected ) { + $this->assertEquals( + $expected, + AvroValidator::getErrors( $schema, $datum ), + $message + ); + } +} -- cgit v1.2.3-54-g00ecf