Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / debug / logger / monolog / AvroFormatterTest.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Logger\Monolog;
22
23 use PHPUnit_Framework_Error_Notice;
24
25 /**
26 * @covers \MediaWiki\Logger\Monolog\AvroFormatter
27 */
28 class AvroFormatterTest extends \MediaWikiUnitTestCase {
29
30 protected function setUp() {
31 if ( !class_exists( 'AvroStringIO' ) ) {
32 $this->markTestSkipped( 'Avro is required for the AvroFormatterTest' );
33 }
34 parent::setUp();
35 }
36
37 public function testSchemaNotAvailable() {
38 $formatter = new AvroFormatter( [] );
39 $this->setExpectedException(
40 'PHPUnit_Framework_Error_Notice',
41 "The schema for channel 'marty' is not available"
42 );
43 $formatter->format( [ 'channel' => 'marty' ] );
44 }
45
46 public function testSchemaNotAvailableReturnValue() {
47 $formatter = new AvroFormatter( [] );
48 $noticeEnabled = PHPUnit_Framework_Error_Notice::$enabled;
49 // disable conversion of notices
50 PHPUnit_Framework_Error_Notice::$enabled = false;
51 // have to keep the user notice from being output
52 \Wikimedia\suppressWarnings();
53 $res = $formatter->format( [ 'channel' => 'marty' ] );
54 \Wikimedia\restoreWarnings();
55 PHPUnit_Framework_Error_Notice::$enabled = $noticeEnabled;
56 $this->assertNull( $res );
57 }
58
59 public function testDoesSomethingWhenSchemaAvailable() {
60 $formatter = new AvroFormatter( [
61 'string' => [
62 'schema' => [ 'type' => 'string' ],
63 'revision' => 1010101,
64 ]
65 ] );
66 $res = $formatter->format( [
67 'channel' => 'string',
68 'context' => 'better to be',
69 ] );
70 $this->assertNotNull( $res );
71 // basically just tell us if avro changes its string encoding, or if
72 // we completely fail to generate a log message.
73 $this->assertEquals( 'AAAAAAAAD2m1GGJldHRlciB0byBiZQ==', base64_encode( $res ) );
74 }
75 }