MediaWiki  1.33.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 
21  public function testXdiffAdler32( $input ) {
22  $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
23  $dhb = new DiffHistoryBlob;
24  $myHash = $dhb->xdiffAdler32( $input );
25  $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
26  "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
27  }
28 
29  public function provideXdiffAdler32() {
30  // Hack non-empty early return since PHPUnit expands this provider before running
31  // the setUp() which marks the test as skipped.
32  if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
33  return [ [ '', 'Empty string' ] ];
34  }
35 
36  return [
37  [ '', 'Empty string' ],
38  [ "\0", 'Null' ],
39  [ "\0\0\0", "Several nulls" ],
40  [ "Hello", "An ASCII string" ],
41  [ str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" ]
42  ];
43  }
44 }
DiffHistoryBlobTest\testXdiffAdler32
testXdiffAdler32( $input)
provideXdiffAdler32 DiffHistoryBlob::xdiffAdler32
Definition: DiffHistoryBlobTest.php:21
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:17
DiffHistoryBlobTest
Definition: DiffHistoryBlobTest.php:3
DiffHistoryBlobTest\provideXdiffAdler32
provideXdiffAdler32()
Definition: DiffHistoryBlobTest.php:29
DiffHistoryBlob\xdiffAdler32
xdiffAdler32( $s)
Compute a binary "Adler-32" checksum as defined by LibXDiff, i.e.
Definition: DiffHistoryBlob.php:272
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:2288
DiffHistoryBlob
Diff-based history compression Requires xdiff 1.5+ and zlib.
Definition: DiffHistoryBlob.php:27