MediaWiki  1.30.0
DiffHistoryBlobTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5  protected function setUp() {
6  parent::setUp();
7 
8  $this->checkPHPExtension( 'hash' );
9  $this->checkPHPExtension( 'xdiff' );
10 
11  if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
12  $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
13  return;
14  }
15  }
16 
22  public function testXdiffAdler32( $input ) {
23  $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
24  $dhb = new DiffHistoryBlob;
25  $myHash = $dhb->xdiffAdler32( $input );
26  $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
27  "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
28  }
29 
30  public function provideXdiffAdler32() {
31  // Hack non-empty early return since PHPUnit expands this provider before running
32  // the setUp() which marks the test as skipped.
33  if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
34  return [ [ '', 'Empty string' ] ];
35  }
36 
37  return [
38  [ '', 'Empty string' ],
39  [ "\0", 'Null' ],
40  [ "\0\0\0", "Several nulls" ],
41  [ "Hello", "An ASCII string" ],
42  [ str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" ]
43  ];
44  }
45 }
DiffHistoryBlobTest\testXdiffAdler32
testXdiffAdler32( $input)
Test for DiffHistoryBlob::xdiffAdler32() provideXdiffAdler32 DiffHistoryBlob::xdiffAdler32.
Definition: DiffHistoryBlobTest.php:22
DiffHistoryBlobTest\setUp
setUp()
Definition: DiffHistoryBlobTest.php:5
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
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
DiffHistoryBlobTest
Definition: DiffHistoryBlobTest.php:3
DiffHistoryBlobTest\provideXdiffAdler32
provideXdiffAdler32()
Definition: DiffHistoryBlobTest.php:30
DiffHistoryBlob\xdiffAdler32
xdiffAdler32( $s)
Compute a binary "Adler-32" checksum as defined by LibXDiff, i.e.
Definition: HistoryBlob.php:595
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1770
DiffHistoryBlob
Diff-based history compression Requires xdiff 1.5+ and zlib.
Definition: HistoryBlob.php:349