3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Logger\Monolog
;
23 use MediaWikiTestCase
;
24 use PHPUnit_Framework_Error_Notice
;
26 class AvroFormatterTest
extends MediaWikiTestCase
{
28 public function setUo() {
29 if ( !class_exists( 'AvroStringIO' ) ) {
30 $this->markTestSkipped( 'Avro is required for the AvroFormatterTest' );
35 public function testSchemaNotAvailable() {
36 $formatter = new AvroFormatter( array() );
37 $this->setExpectedException( 'PHPUnit_Framework_Error_Notice', "The schema for channel 'marty' is not available" );
38 $formatter->format( array( 'channel' => 'marty' ) );
41 public function testSchemaNotAvailableReturnValue() {
42 $formatter = new AvroFormatter( array() );
43 $noticeEnabled = PHPUnit_Framework_Error_Notice
::$enabled;
44 // disable conversion of notices
45 PHPUnit_Framework_Error_Notice
::$enabled = false;
46 // have to keep the user notice from being output
48 $res = $formatter->format( array( 'channel' => 'marty' ) );
50 PHPUnit_Framework_Error_Notice
::$enabled = $noticeEnabled;
51 $this->assertNull( $res );
54 public function testDoesSomethingWhenSchemaAvailable() {
55 $formatter = new AvroFormatter( array( 'string' => array( 'type' => 'string' ) ) );
56 $res = $formatter->format( array(
57 'channel' => 'string',
58 'context' => 'better to be',
60 $this->assertNotNull( $res );
61 // basically just tell us if avro changes its string encoding
62 $this->assertEquals( base64_decode( 'GGJldHRlciB0byBiZQ==' ), $res );