MediaWiki REL1_31
AvroFormatterTest.php
Go to the documentation of this file.
1<?php
22
24use PHPUnit_Framework_Error_Notice;
25
30
31 protected function setUp() {
32 if ( !class_exists( 'AvroStringIO' ) ) {
33 $this->markTestSkipped( 'Avro is required for the AvroFormatterTest' );
34 }
35 parent::setUp();
36 }
37
38 public function testSchemaNotAvailable() {
39 $formatter = new AvroFormatter( [] );
40 $this->setExpectedException(
41 'PHPUnit_Framework_Error_Notice',
42 "The schema for channel 'marty' is not available"
43 );
44 $formatter->format( [ 'channel' => 'marty' ] );
45 }
46
48 $formatter = new AvroFormatter( [] );
49 $noticeEnabled = PHPUnit_Framework_Error_Notice::$enabled;
50 // disable conversion of notices
51 PHPUnit_Framework_Error_Notice::$enabled = false;
52 // have to keep the user notice from being output
53 \Wikimedia\suppressWarnings();
54 $res = $formatter->format( [ 'channel' => 'marty' ] );
55 \Wikimedia\restoreWarnings();
56 PHPUnit_Framework_Error_Notice::$enabled = $noticeEnabled;
57 $this->assertNull( $res );
58 }
59
61 $formatter = new AvroFormatter( [
62 'string' => [
63 'schema' => [ 'type' => 'string' ],
64 'revision' => 1010101,
65 ]
66 ] );
67 $res = $formatter->format( [
68 'channel' => 'string',
69 'context' => 'better to be',
70 ] );
71 $this->assertNotNull( $res );
72 // basically just tell us if avro changes its string encoding, or if
73 // we completely fail to generate a log message.
74 $this->assertEquals( 'AAAAAAAAD2m1GGJldHRlciB0byBiZQ==', base64_encode( $res ) );
75 }
76}
\MediaWiki\Logger\Monolog\AvroFormatter
Log message formatter that uses the apache Avro format.
$res
Definition database.txt:21