Add @covers tags to includes/debug tests
[lhc/web/wiklou.git] / tests / phpunit / 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 MediaWikiTestCase;
24 use PHPUnit_Framework_Error_Notice;
25
26 /**
27 * @covers \MediaWiki\Logger\Monolog\AvroFormatter
28 */
29 class AvroFormatterTest extends MediaWikiTestCase {
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
47 public function testSchemaNotAvailableReturnValue() {
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 \MediaWiki\suppressWarnings();
54 $res = $formatter->format( [ 'channel' => 'marty' ] );
55 \MediaWiki\restoreWarnings();
56 PHPUnit_Framework_Error_Notice::$enabled = $noticeEnabled;
57 $this->assertNull( $res );
58 }
59
60 public function testDoesSomethingWhenSchemaAvailable() {
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 }