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

Commit 07e6e4c

Browse files
committed
Merge branch 'hotfix/52'
Close #52
2 parents 04e01a7 + 31abf1b commit 07e6e4c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ All notable changes to this project will be documented in this file, in reverse
2424
aliases for the i18n isfloat/isint validators.
2525
- Updates the hostname validator regexes per the canonical service on which they
2626
are based.
27+
- [#52](https://github.com/zendframework/zend-validator/pull/52) updates the
28+
`Barcode` validator to cast empty options passed to the constructor to an
29+
empty array, fixing type mismatch errors.
2730

2831
## 2.5.3 - 2015-09-03
2932

src/Barcode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class Barcode extends AbstractValidator
4848
*/
4949
public function __construct($options = null)
5050
{
51+
if ($options === null) {
52+
$options = [];
53+
}
54+
5155
if (!is_array($options) && !($options instanceof Traversable)) {
5256
$options = ['adapter' => $options];
5357
}

test/BarcodeTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@
1818
*/
1919
class BarcodeTest extends \PHPUnit_Framework_TestCase
2020
{
21+
public function provideBarcodeConstructor()
22+
{
23+
return [
24+
'null' => [null, Barcode\Ean13::class],
25+
'empty-array' => [[], Barcode\Ean13::class],
26+
];
27+
}
28+
/**
29+
* @dataProvider provideBarcodeConstructor
30+
*/
31+
public function testBarcodeConstructor($options, $expectedInstance)
32+
{
33+
$barcode = new Barcode($options);
34+
$this->assertInstanceOf($expectedInstance, $barcode->getAdapter());
35+
}
36+
2137
public function testNoneExisting()
2238
{
2339
$this->setExpectedException('Zend\Validator\Exception\InvalidArgumentException', 'not found');
@@ -466,14 +482,20 @@ public function testEan13ContainsOnlyNumeric()
466482
public function testEqualsMessageTemplates()
467483
{
468484
$validator = new Barcode('code25');
469-
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
470-
'messageTemplates', $validator);
485+
$this->assertAttributeEquals(
486+
$validator->getOption('messageTemplates'),
487+
'messageTemplates',
488+
$validator
489+
);
471490
}
472491

473492
public function testEqualsMessageVariables()
474493
{
475494
$validator = new Barcode('code25');
476-
$this->assertAttributeEquals($validator->getOption('messageVariables'),
477-
'messageVariables', $validator);
495+
$this->assertAttributeEquals(
496+
$validator->getOption('messageVariables'),
497+
'messageVariables',
498+
$validator
499+
);
478500
}
479501
}

0 commit comments

Comments
 (0)