From f3f875f265d2b9ad142a94612173064a6c0b90a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Kutn=C3=BD?= Date: Wed, 17 Jul 2024 22:41:16 +0200 Subject: [PATCH] Add failint test for invalid ITF14 checksum --- tests/ChecksumBarcodeTest.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/ChecksumBarcodeTest.php b/tests/ChecksumBarcodeTest.php index 2bbf0db..4298211 100644 --- a/tests/ChecksumBarcodeTest.php +++ b/tests/ChecksumBarcodeTest.php @@ -1,13 +1,14 @@ TypeEan13::class, 'barcodes' => [ '081231723897' => '0812317238973', '004900000463' => '0049000004632', @@ -17,14 +18,30 @@ class ChecksumBarcodeTest extends TestCase '0540014128876' => '05400141288766', ]], ]; + private const INVALID_BARCODES = [ + ['type' => TypeEan13::class, 'barcodes' => ['0812317238972', '0049000004633']], + ['type' => TypeITF14::class, 'barcodes' => ['00012345600016', '05400141288762']], + ]; + + public function testAllValidBarcodeTypes() + { + foreach (self::VALID_BARCODES as $barcodeTestSet) { + $barcodeType = $this->getBarcodeType($barcodeTestSet['type']); + + foreach ($barcodeTestSet['barcodes'] as $testBarcode => $validBarcode) { + $this->assertEquals($validBarcode, $barcodeType->getBarcodeData($testBarcode)->getBarcode()); + } + } + } - public function testAllSupportedBarcodeTypes() + public function testAllInvalidBarcodeTypes() { - foreach ($this::$supportedBarcodes as $barcodeTestSet) { + foreach (self::INVALID_BARCODES as $barcodeTestSet) { $barcodeType = $this->getBarcodeType($barcodeTestSet['type']); - foreach ($barcodeTestSet['barcodes'] as $testBarcode => $expectedBarcode) { - $this->assertEquals($expectedBarcode, $barcodeType->getBarcodeData($testBarcode)->getBarcode()); + foreach ($barcodeTestSet['barcodes'] as $invalidBarcode) { + $this->expectException(InvalidCheckDigitException::class); + $barcodeType->getBarcodeData($invalidBarcode)->getBarcode(); } } }