From 9612d5045c2887aba1d1e863d07ddce1ec73b078 Mon Sep 17 00:00:00 2001 From: Leith Caldwell Date: Fri, 17 Jun 2016 13:55:17 +1200 Subject: [PATCH] Add unit tests for Item subclass, make sure price is always an int --- src/Item.php | 2 ++ tests/ItemTest.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/ItemTest.php diff --git a/src/Item.php b/src/Item.php index 98b2977..b8394c0 100644 --- a/src/Item.php +++ b/src/Item.php @@ -95,6 +95,8 @@ public function setPrice($value) // @todo would be nicer if this could be done with AbstractRequest currency functions (or similar) if (is_float($value) || (is_string($value) && strpos($value, '.') !== false)) { $value = (int) round($value * 100); + } else { + $value = (int) $value; } return parent::setPrice($value); diff --git a/tests/ItemTest.php b/tests/ItemTest.php new file mode 100644 index 0000000..da52eed --- /dev/null +++ b/tests/ItemTest.php @@ -0,0 +1,53 @@ +item = new Item; + } + + public function testFundCode() + { + $this->item->setFundCode('123'); + $this->assertSame('123', $this->item->getFundCode()); + } + + public function testCustRef1() + { + $this->item->setCustRef1('Test item'); + $this->assertSame('Test item', $this->item->getCustRef1()); + } + + public function testCustRef2() + { + $this->item->setCustRef2('Test item'); + $this->assertSame('Test item', $this->item->getCustRef2()); + } + + public function testCustRef3() + { + $this->item->setCustRef3('Test item'); + $this->assertSame('Test item', $this->item->getCustRef3()); + } + + public function testCustRef4() + { + $this->item->setCustRef4('Test item'); + $this->assertSame('Test item', $this->item->getCustRef4()); + } + + public function testPrice() + { + $this->item->setPrice('10.01'); + $this->assertSame(1001, $this->item->getPrice()); + $this->item->setPrice(10.02); + $this->assertSame(1002, $this->item->getPrice()); + $this->item->setPrice('1003'); + $this->assertSame(1003, $this->item->getPrice()); + } +}