Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / debug / logger / monolog / AvroFormatterTest.php
blob938397ab1f8101f51e4c57a461e540d09571ee50
1 <?php
2 /**
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
18 * @file
21 namespace MediaWiki\Logger\Monolog;
23 use MediaWikiTestCase;
24 use PHPUnit_Framework_Error_Notice;
26 class AvroFormatterTest extends MediaWikiTestCase {
28 protected function setUp() {
29 if ( !class_exists( 'AvroStringIO' ) ) {
30 $this->markTestSkipped( 'Avro is required for the AvroFormatterTest' );
32 parent::setUp();
35 public function testSchemaNotAvailable() {
36 $formatter = new AvroFormatter( [] );
37 $this->setExpectedException(
38 'PHPUnit_Framework_Error_Notice',
39 "The schema for channel 'marty' is not available"
41 $formatter->format( [ 'channel' => 'marty' ] );
44 public function testSchemaNotAvailableReturnValue() {
45 $formatter = new AvroFormatter( [] );
46 $noticeEnabled = PHPUnit_Framework_Error_Notice::$enabled;
47 // disable conversion of notices
48 PHPUnit_Framework_Error_Notice::$enabled = false;
49 // have to keep the user notice from being output
50 \MediaWiki\suppressWarnings();
51 $res = $formatter->format( [ 'channel' => 'marty' ] );
52 \MediaWiki\restoreWarnings();
53 PHPUnit_Framework_Error_Notice::$enabled = $noticeEnabled;
54 $this->assertNull( $res );
57 public function testDoesSomethingWhenSchemaAvailable() {
58 $formatter = new AvroFormatter( [
59 'string' => [
60 'schema' => [ 'type' => 'string' ],
61 'revision' => 1010101,
63 ] );
64 $res = $formatter->format( [
65 'channel' => 'string',
66 'context' => 'better to be',
67 ] );
68 $this->assertNotNull( $res );
69 // basically just tell us if avro changes its string encoding, or if
70 // we completely fail to generate a log message.
71 $this->assertEquals( 'AAAAAAAAD2m1GGJldHRlciB0byBiZQ==', base64_encode( $res ) );