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/6576'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 20, 2014
2 parents 9f6a11a + 506c531 commit 2ab49f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/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 test/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 2ab49f1

Please sign in to comment.