MediaWiki  1.30.2
AvroFormatterTest.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Logger\Monolog;
22 
24 use PHPUnit_Framework_Error_Notice;
25 
27 
28  protected function setUp() {
29  if ( !class_exists( 'AvroStringIO' ) ) {
30  $this->markTestSkipped( 'Avro is required for the AvroFormatterTest' );
31  }
32  parent::setUp();
33  }
34 
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"
40  );
41  $formatter->format( [ 'channel' => 'marty' ] );
42  }
43 
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 );
55  }
56 
58  $formatter = new AvroFormatter( [
59  'string' => [
60  'schema' => [ 'type' => 'string' ],
61  'revision' => 1010101,
62  ]
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 ) );
72  }
73 }
MediaWiki\Logger\Monolog\AvroFormatterTest\testSchemaNotAvailable
testSchemaNotAvailable()
Definition: AvroFormatterTest.php:35
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$res
$res
Definition: database.txt:21
MediaWiki\Logger\Monolog
Definition: AvroFormatter.php:21
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Logger\Monolog\AvroFormatter
Log message formatter that uses the apache Avro format.
Definition: AvroFormatter.php:38
MediaWiki\Logger\Monolog\AvroFormatterTest\setUp
setUp()
Definition: AvroFormatterTest.php:28
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
MediaWiki\Logger\Monolog\AvroFormatterTest\testDoesSomethingWhenSchemaAvailable
testDoesSomethingWhenSchemaAvailable()
Definition: AvroFormatterTest.php:57
MediaWiki\Logger\Monolog\AvroFormatterTest
Definition: AvroFormatterTest.php:26
MediaWiki\Logger\Monolog\AvroFormatterTest\testSchemaNotAvailableReturnValue
testSchemaNotAvailableReturnValue()
Definition: AvroFormatterTest.php:44