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

Commit

Permalink
Merge branch 'hotfix/6576' into develop
Browse files Browse the repository at this point in the history
Forward port #6576
  • Loading branch information
weierophinney committed Aug 20, 2014
2 parents 93b57e1 + 9121935 commit 766fd11
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions library/Zend/Validator/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,20 @@ public function setAdapter($adapter, $options = null)
throw new Exception\InvalidArgumentException('Barcode adapter matching "' . $adapter . '" not found');
}

$this->options['adapter'] = new $adapter($options);
$adapter = new $adapter($options);
}

if (!$this->options['adapter'] instanceof Barcode\AdapterInterface) {
if (!$adapter instanceof Barcode\AdapterInterface) {
throw new Exception\InvalidArgumentException(
"Adapter $adapter does not implement Zend\\Validate\\Barcode\\AdapterInterface"
sprintf(
"Adapter %s does not implement Zend\\Validator\\Barcode\\AdapterInterface",
(is_object($adapter) ? get_class($adapter) : gettype($adapter))
)
);
}

$this->options['adapter'] = $adapter;

return $this;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ZendTest/Validator/BarcodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public function testSetAdapter()
$this->assertTrue($barcode->isValid('0075678164125'));
}

public function testSetCustomAdapter()
{
$barcode = new Barcode(array(
'adapter' => $this->getMock('Zend\Validator\Barcode\AdapterInterface')
));

$this->assertInstanceOf('Zend\Validator\Barcode\AdapterInterface', $barcode->getAdapter());
}

/**
* @ZF-4352
*/
Expand Down

0 comments on commit 766fd11

Please sign in to comment.