Debian Codegraph @

tests/phpunit/includes/utils/FileContentsHasherTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * @covers \FileContentsHasher
5 */
6 class FileContentsHasherTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
10 public static function provideSingleFile() {
11 return array_map( static function ( $file ) {
12 return [ $file, file_get_contents( $file ) ];
13 }, glob( __DIR__ . '/../../data/filecontentshasher/*.*' ) );
14 }
15
16 /**
17 * @dataProvider provideSingleFile
18 */
19 public function testSingleFileHash( $fileName, $contents ) {
20 $expected = hash( 'md4', $contents );
21 $actualHash = FileContentsHasher::getFileContentsHash( $fileName );
22 $this->assertEquals( $expected, $actualHash );
23
24 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileName );
25 $this->assertEquals( $expected, $actualHashRepeat );
26 }
27
28 public function provideMultipleFiles() {
29 return [
30 [ $this->provideSingleFile() ]
31 ];
32 }
33
34 /**
35 * @dataProvider provideMultipleFiles
36 */
37 public function testMultipleFileHash( $files ) {
38 $fileNames = [];
39 $hashes = [];
40 foreach ( $files as [ $fileName, $contents ] ) {
41 $fileNames[] = $fileName;
42 $hashes[] = hash( 'md4', $contents );
43 }
44
45 $expectedHash = hash( 'md4', implode( '', $hashes ) );
46 $actualHash = FileContentsHasher::getFileContentsHash( $fileNames );
47 $this->assertEquals( $expectedHash, $actualHash );
48
49 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileNames );
50 $this->assertEquals( $expectedHash, $actualHashRepeat );
51 }
52 }