4 * @covers \FileContentsHasher
6 class FileContentsHasherTest
extends PHPUnit\Framework\TestCase
{
8 use MediaWikiCoversValidator
;
10 public static function provideSingleFile() {
11 return array_map( static function ( $file ) {
12 return [ $file, file_get_contents( $file ) ];
13 }, glob( __DIR__
. '/../../data/filecontentshasher/*.*' ) );
17 * @dataProvider provideSingleFile
19 public function testSingleFileHash( $fileName, $contents ) {
20 $expected = hash( 'md4', $contents );
21 $actualHash = FileContentsHasher
::getFileContentsHash( $fileName );
22 $this->assertEquals( $expected, $actualHash );
24 $actualHashRepeat = FileContentsHasher
::getFileContentsHash( $fileName );
25 $this->assertEquals( $expected, $actualHashRepeat );
28 public function provideMultipleFiles() {
30 [ $this->provideSingleFile() ]
35 * @dataProvider provideMultipleFiles
37 public function testMultipleFileHash( $files ) {
40 foreach ( $files as [ $fileName, $contents ] ) {
41 $fileNames[] = $fileName;
42 $hashes[] = hash( 'md4', $contents );
45 $expectedHash = hash( 'md4', implode( '', $hashes ) );
46 $actualHash = FileContentsHasher
::getFileContentsHash( $fileNames );
47 $this->assertEquals( $expectedHash, $actualHash );
49 $actualHashRepeat = FileContentsHasher
::getFileContentsHash( $fileNames );
50 $this->assertEquals( $expectedHash, $actualHashRepeat );