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

Commit 7d0cf83

Browse files
committed
Merge pull request #231 from adamoki/patch-1
Correcting validation error
2 parents 1eab945 + 5f28b5a commit 7d0cf83

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/File/Hash.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public function addHash($options)
117117
}
118118

119119
foreach ($options as $value) {
120+
if (! is_string($value)) {
121+
throw new Exception\InvalidArgumentException(sprintf(
122+
'Hash must be a string, %s received',
123+
is_object($value) ? get_class($value) : gettype($value)
124+
));
125+
}
120126
$this->options['hash'][$value] = $algorithm;
121127
}
122128

test/File/HashTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,18 @@ public function testConstructorCanAcceptAllOptionsAsDiscreteArguments()
239239
$options = $r->getValue($validator);
240240
$this->assertSame($algorithm, $options['algorithm']);
241241
}
242+
243+
/**
244+
* @dataProvider invalidHashTypes
245+
*
246+
* @param mixed $hash
247+
*/
248+
public function testInvalidHashProvidedInArrayFormat($hash)
249+
{
250+
$validator = new File\Hash('12345');
251+
252+
$this->expectException(InvalidArgumentException::class);
253+
$this->expectExceptionMessage('Hash must be a string');
254+
$validator->addHash([$hash]);
255+
}
242256
}

0 commit comments

Comments
 (0)