X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/phpunit/includes/debug/logger/monolog/AvroFormatterTest.php diff --git a/tests/phpunit/includes/debug/logger/monolog/AvroFormatterTest.php b/tests/phpunit/includes/debug/logger/monolog/AvroFormatterTest.php new file mode 100644 index 00000000..938397ab --- /dev/null +++ b/tests/phpunit/includes/debug/logger/monolog/AvroFormatterTest.php @@ -0,0 +1,73 @@ +markTestSkipped( 'Avro is required for the AvroFormatterTest' ); + } + parent::setUp(); + } + + public function testSchemaNotAvailable() { + $formatter = new AvroFormatter( [] ); + $this->setExpectedException( + 'PHPUnit_Framework_Error_Notice', + "The schema for channel 'marty' is not available" + ); + $formatter->format( [ 'channel' => 'marty' ] ); + } + + public function testSchemaNotAvailableReturnValue() { + $formatter = new AvroFormatter( [] ); + $noticeEnabled = PHPUnit_Framework_Error_Notice::$enabled; + // disable conversion of notices + PHPUnit_Framework_Error_Notice::$enabled = false; + // have to keep the user notice from being output + \MediaWiki\suppressWarnings(); + $res = $formatter->format( [ 'channel' => 'marty' ] ); + \MediaWiki\restoreWarnings(); + PHPUnit_Framework_Error_Notice::$enabled = $noticeEnabled; + $this->assertNull( $res ); + } + + public function testDoesSomethingWhenSchemaAvailable() { + $formatter = new AvroFormatter( [ + 'string' => [ + 'schema' => [ 'type' => 'string' ], + 'revision' => 1010101, + ] + ] ); + $res = $formatter->format( [ + 'channel' => 'string', + 'context' => 'better to be', + ] ); + $this->assertNotNull( $res ); + // basically just tell us if avro changes its string encoding, or if + // we completely fail to generate a log message. + $this->assertEquals( 'AAAAAAAAD2m1GGJldHRlciB0byBiZQ==', base64_encode( $res ) ); + } +}