4 * @covers FileContentsHasherTest
6 class FileContentsHasherTest
extends PHPUnit\Framework\TestCase
{
8 use MediaWikiCoversValidator
;
10 public function provideSingleFile() {
11 return array_map( function ( $file ) {
12 return [ $file, file_get_contents( $file ) ];
13 }, glob( __DIR__
. '/../../data/filecontentshasher/*.*' ) );
16 public function provideMultipleFiles() {
18 [ $this->provideSingleFile() ]
23 * @covers FileContentsHasher::getFileContentsHash
24 * @covers FileContentsHasher::getFileContentsHashInternal
25 * @dataProvider provideSingleFile
27 public function testSingleFileHash( $fileName, $contents ) {
28 foreach ( [ 'md4', 'md5' ] as $algo ) {
29 $expectedHash = hash( $algo, $contents );
30 $actualHash = FileContentsHasher
::getFileContentsHash( $fileName, $algo );
31 $this->assertEquals( $expectedHash, $actualHash );
32 $actualHashRepeat = FileContentsHasher
::getFileContentsHash( $fileName, $algo );
33 $this->assertEquals( $expectedHash, $actualHashRepeat );
38 * @covers FileContentsHasher::getFileContentsHash
39 * @covers FileContentsHasher::getFileContentsHashInternal
40 * @dataProvider provideMultipleFiles
42 public function testMultipleFileHash( $files ) {
45 foreach ( $files as $fileInfo ) {
46 list( $fileName, $contents ) = $fileInfo;
47 $fileNames[] = $fileName;
48 $hashes[] = md5( $contents );
51 $expectedHash = md5( implode( '', $hashes ) );
52 $actualHash = FileContentsHasher
::getFileContentsHash( $fileNames, 'md5' );
53 $this->assertEquals( $expectedHash, $actualHash );
54 $actualHashRepeat = FileContentsHasher
::getFileContentsHash( $fileNames, 'md5' );
55 $this->assertEquals( $expectedHash, $actualHashRepeat );