Skip to content

Commit c6bae34

Browse files
authored
Merge pull request #100 from MarkusPoutanen/fix-item-vat-validation
Item: Add validation for empty vatPercentage
2 parents 9b2f3a6 + 4fb08fe commit c6bae34

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Model/Item.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ public function validate()
388388
if ($props['units'] < 0) {
389389
throw new ValidationException('Items units can\'t be a negative number');
390390
}
391+
if ($props['vatPercentage'] === null) {
392+
throw new ValidationException('Item vatPercentage is empty');
393+
}
391394
if ($props['vatPercentage'] < 0) {
392395
throw new ValidationException('Items vatPercentage can\'t be a negative number');
393396
}

tests/Model/ItemTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function testItemWithNegativeUnitsThrowsError()
5757
->validate();
5858
}
5959

60+
public function testItemWithoutVatThrowsError()
61+
{
62+
$this->expectException(ValidationException::class);
63+
(new Item())->setUnitPrice(1)
64+
->setUnits(2)
65+
->setStamp('thisIsStamp')
66+
->setProductCode('productCode123')
67+
->setDescription('description')
68+
->validate();
69+
}
70+
6071
public function testItemWIthNegativeVatThrowsError()
6172
{
6273
$this->expectException(ValidationException::class);

0 commit comments

Comments
 (0)