4 * @covers FileContentsHasherTest
6 class FileContentsHasherTest
extends PHPUnit_Framework_TestCase
{
8 public function provideSingleFile() {
9 return array_map( function ( $file ) {
10 return [ $file, file_get_contents( $file ) ];
11 }, glob( __DIR__
. '/../../data/filecontentshasher/*.*' ) );
14 public function provideMultipleFiles() {
16 [ $this->provideSingleFile() ]
21 * @covers FileContentsHasher::getFileContentsHash
22 * @covers FileContentsHasher::getFileContentsHashInternal
23 * @dataProvider provideSingleFile
25 public function testSingleFileHash( $fileName, $contents ) {
26 foreach ( [ 'md4', 'md5' ] as $algo ) {
27 $expectedHash = hash( $algo, $contents );
28 $actualHash = FileContentsHasher
::getFileContentsHash( $fileName, $algo );
29 $this->assertEquals( $expectedHash, $actualHash );
30 $actualHashRepeat = FileContentsHasher
::getFileContentsHash( $fileName, $algo );
31 $this->assertEquals( $expectedHash, $actualHashRepeat );
36 * @covers FileContentsHasher::getFileContentsHash
37 * @covers FileContentsHasher::getFileContentsHashInternal
38 * @dataProvider provideMultipleFiles
40 public function testMultipleFileHash( $files ) {
43 foreach ( $files as $fileInfo ) {
44 list( $fileName, $contents ) = $fileInfo;
45 $fileNames[] = $fileName;
46 $hashes[] = md5( $contents );
49 $expectedHash = md5( implode( '', $hashes ) );
50 $actualHash = FileContentsHasher
::getFileContentsHash( $fileNames, 'md5' );
51 $this->assertEquals( $expectedHash, $actualHash );
52 $actualHashRepeat = FileContentsHasher
::getFileContentsHash( $fileNames, 'md5' );
53 $this->assertEquals( $expectedHash, $actualHashRepeat );