Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #231 from adamoki/patch-1
Browse files Browse the repository at this point in the history
Correcting validation error
  • Loading branch information
michalbundyra committed Oct 12, 2019
2 parents 1eab945 + 5f28b5a commit 7d0cf83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/File/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public function addHash($options)
}

foreach ($options as $value) {
if (! is_string($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Hash must be a string, %s received',
is_object($value) ? get_class($value) : gettype($value)
));
}
$this->options['hash'][$value] = $algorithm;
}

Expand Down
14 changes: 14 additions & 0 deletions test/File/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,18 @@ public function testConstructorCanAcceptAllOptionsAsDiscreteArguments()
$options = $r->getValue($validator);
$this->assertSame($algorithm, $options['algorithm']);
}

/**
* @dataProvider invalidHashTypes
*
* @param mixed $hash
*/
public function testInvalidHashProvidedInArrayFormat($hash)
{
$validator = new File\Hash('12345');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Hash must be a string');
$validator->addHash([$hash]);
}
}

0 comments on commit 7d0cf83

Please sign in to comment.