MediaWiki REL1_28
AvroValidatorTest.php
Go to the documentation of this file.
1<?php
12class AvroValidatorTest extends PHPUnit_Framework_TestCase {
13 public function setUp() {
14 if ( !class_exists( 'AvroSchema' ) ) {
15 $this->markTestSkipped( 'Avro is required to run the AvroValidatorTest' );
16 }
17 parent::setUp();
18 }
19
20 public function getErrorsProvider() {
21 $stringSchema = AvroSchema::parse( json_encode( [ 'type' => 'string' ] ) );
22 $stringArraySchema = AvroSchema::parse( json_encode( [
23 'type' => 'array',
24 'items' => 'string',
25 ] ) );
26 $recordSchema = AvroSchema::parse( json_encode( [
27 'type' => 'record',
28 'name' => 'ut',
29 'fields' => [
30 [ 'name' => 'id', 'type' => 'int', 'required' => true ],
31 ],
32 ] ) );
33 $enumSchema = AvroSchema::parse( json_encode( [
34 'type' => 'record',
35 'name' => 'ut',
36 'fields' => [
37 [ 'name' => 'count', 'type' => [ 'int', 'null' ] ],
38 ],
39 ] ) );
40
41 return [
42 [
43 'No errors with a simple string serialization',
44 $stringSchema, 'foobar', [],
45 ],
46
47 [
48 'Cannot serialize integer into string',
49 $stringSchema, 5, 'Expected string, but recieved integer',
50 ],
51
52 [
53 'Cannot serialize array into string',
54 $stringSchema, [], 'Expected string, but recieved array',
55 ],
56
57 [
58 'allows and ignores extra fields',
59 $recordSchema, [ 'id' => 4, 'foo' => 'bar' ], [],
60 ],
61
62 [
63 'detects missing fields',
64 $recordSchema, [], [ 'id' => 'Missing expected field' ],
65 ],
66
67 [
68 'handles first element in enum',
69 $enumSchema, [ 'count' => 4 ], [],
70 ],
71
72 [
73 'handles second element in enum',
74 $enumSchema, [ 'count' => null ], [],
75 ],
76
77 [
78 'rejects element not in union',
79 $enumSchema, [ 'count' => 'invalid' ], [ 'count' => [
80 'Expected any one of these to be true',
81 [
82 'Expected integer, but recieved string',
83 'Expected null, but recieved string',
84 ]
85 ] ]
86 ],
87 [
88 'Empty array is accepted',
89 $stringArraySchema, [], []
90 ],
91 [
92 'correct array element accepted',
93 $stringArraySchema, [ 'fizzbuzz' ], []
94 ],
95 [
96 'incorrect array element rejected',
97 $stringArraySchema, [ '12', 34 ], [ 'Expected string, but recieved integer' ]
98 ],
99 ];
100 }
101
105 public function testGetErrors( $message, $schema, $datum, $expected ) {
106 $this->assertEquals(
107 $expected,
108 AvroValidator::getErrors( $schema, $datum ),
109 $message
110 );
111 }
112}
Tests for IP validity functions.
testGetErrors( $message, $schema, $datum, $expected)
getErrorsProvider
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37