Skip to content

Commit

Permalink
Fix generating Pharmacode 2 with invalid input #118
Browse files Browse the repository at this point in the history
  • Loading branch information
casperbakker committed Dec 24, 2020
1 parent 5cae7eb commit 2221d83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Types/TypePharmacodeTwoCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

use Picqer\Barcode\Barcode;
use Picqer\Barcode\BarcodeBar;
use Picqer\Barcode\Exceptions\InvalidLengthException;

class TypePharmacodeTwoCode implements TypeInterface
{
public function getBarcodeData(string $code): Barcode
{
$code = intval($code);

if ($code < 1) {
throw new InvalidLengthException('Pharmacode 2 needs a number of 1 or larger');
}

$seq = '';

do {
Expand Down
15 changes: 15 additions & 0 deletions tests/PharmacodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use PHPUnit\Framework\TestCase;

class PharmacodeTest extends TestCase
{
public function test_validation_triggerd_when_generating_zero_code()
{
$pharmacode = new Picqer\Barcode\Types\TypePharmacodeTwoCode();

$this->expectException(Picqer\Barcode\Exceptions\InvalidLengthException::class);

$pharmacode->getBarcodeData('0');
}
}

0 comments on commit 2221d83

Please sign in to comment.