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

Commit

Permalink
Merge branch 'hotfix/52' into develop
Browse files Browse the repository at this point in the history
Forward port #52
  • Loading branch information
weierophinney committed Feb 17, 2016
2 parents 5f0b010 + 31abf1b commit 16e518d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ All notable changes to this project will be documented in this file, in reverse
aliases for the i18n isfloat/isint validators.
- Updates the hostname validator regexes per the canonical service on which they
are based.
- [#52](https://github.com/zendframework/zend-validator/pull/52) updates the
`Barcode` validator to cast empty options passed to the constructor to an
empty array, fixing type mismatch errors.

## 2.5.3 - 2015-09-03

Expand Down
4 changes: 4 additions & 0 deletions src/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Barcode extends AbstractValidator
*/
public function __construct($options = null)
{
if ($options === null) {
$options = [];
}

if (!is_array($options) && !($options instanceof Traversable)) {
$options = ['adapter' => $options];
}
Expand Down
30 changes: 26 additions & 4 deletions test/BarcodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
*/
class BarcodeTest extends \PHPUnit_Framework_TestCase
{
public function provideBarcodeConstructor()
{
return [
'null' => [null, Barcode\Ean13::class],
'empty-array' => [[], Barcode\Ean13::class],
];
}
/**
* @dataProvider provideBarcodeConstructor
*/
public function testBarcodeConstructor($options, $expectedInstance)
{
$barcode = new Barcode($options);
$this->assertInstanceOf($expectedInstance, $barcode->getAdapter());
}

public function testNoneExisting()
{
$this->setExpectedException('Zend\Validator\Exception\InvalidArgumentException', 'not found');
Expand Down Expand Up @@ -466,14 +482,20 @@ public function testEan13ContainsOnlyNumeric()
public function testEqualsMessageTemplates()
{
$validator = new Barcode('code25');
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
$this->assertAttributeEquals(
$validator->getOption('messageTemplates'),
'messageTemplates',
$validator
);
}

public function testEqualsMessageVariables()
{
$validator = new Barcode('code25');
$this->assertAttributeEquals($validator->getOption('messageVariables'),
'messageVariables', $validator);
$this->assertAttributeEquals(
$validator->getOption('messageVariables'),
'messageVariables',
$validator
);
}
}

0 comments on commit 16e518d

Please # to comment.