Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
Add unit tests for Item subclass, make sure price is always an int
Browse files Browse the repository at this point in the history
  • Loading branch information
leith committed Jun 17, 2016
1 parent 7fae043 commit 9612d50
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 53 additions & 0 deletions tests/ItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Omnipay\EpsomAdelante;

use Omnipay\Tests\TestCase;

class ItemTest extends TestCase
{
public function setUp()
{
$this->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());
}
}

0 comments on commit 9612d50

Please sign in to comment.