mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-16 20:08:41 +00:00
Draft @testdox example
This commit is contained in:
parent
49cb38ff4f
commit
af77f42eeb
|
|
@ -18,12 +18,17 @@ require_once __DIR__ . '/../Autoloader.php';
|
|||
use phpOMS\Localization\ISO4217SymbolEnum;
|
||||
use phpOMS\Localization\Money;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\Localization\Money: Money datatype for internal representation of money
|
||||
*/
|
||||
class MoneyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefault() : void
|
||||
/**
|
||||
* @testdox The datatype has the expected member variables and default values.
|
||||
*/
|
||||
public function testDefaultMemberVariables() : void
|
||||
{
|
||||
$money = new Money(0);
|
||||
|
||||
self::assertObjectHasAttribute('thousands', $money);
|
||||
self::assertObjectHasAttribute('decimal', $money);
|
||||
self::assertObjectHasAttribute('value', $money);
|
||||
|
|
@ -33,37 +38,76 @@ class MoneyTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(0, $money->getInt());
|
||||
}
|
||||
|
||||
public function testMoney() : void
|
||||
/**
|
||||
* @testdox The datatype returns the correct default string representation (#,###.##)
|
||||
*/
|
||||
public function testMoneyDefaultStringRepresentation() : void
|
||||
{
|
||||
$money = new Money(12345678);
|
||||
|
||||
self::assertEquals('1,234.57', $money->getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datatype returns up to 4 decimal places if requested (#,###.####)
|
||||
*/
|
||||
public function testMoneyDecimalPlaces() : void
|
||||
{
|
||||
$money = new Money(12345678);
|
||||
self::assertEquals('1,234.5678', $money->getAmount(4));
|
||||
self::assertEquals('1,234.5678', $money->getAmount(7));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datatype returns the correct integer representation of a string with up to 4 decimal places also considering differences in decimal and thousands characters if requested for different localizations
|
||||
*/
|
||||
public function testMoneyStringToIntConversion() : void
|
||||
{
|
||||
self::assertEquals(12345678, Money::toInt('1234.5678'));
|
||||
self::assertEquals(12345600, Money::toInt('1,234.56'));
|
||||
self::assertEquals(12345600, Money::toInt('1234,56', '.', ','));
|
||||
}
|
||||
|
||||
public function testMoneySetters() : void
|
||||
/**
|
||||
* @testdox The datatype allows to modify the value by overwriting it with new string characters or integers correctly
|
||||
*/
|
||||
public function testCorrectValueChange() : void
|
||||
{
|
||||
$money = new Money(12345678);
|
||||
self::assertEquals('999.13', $money->setString('999.13')->getAmount());
|
||||
self::assertEquals('999.23', $money->setInt(9992300)->getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datatype can print out money with different thousands, decimals and currency symbols as per definition by the user
|
||||
*/
|
||||
public function testMoneyLocalization() : void
|
||||
{
|
||||
$money = new Money(12345678);
|
||||
self::assertEquals('€9.992,30', $money->setInt(99923000)->setLocalization('.', ',', ISO4217SymbolEnum::_EUR, 0)->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The string character input is correctly serialized to the numeric representation
|
||||
*/
|
||||
public function testMoneySerialization() : void
|
||||
{
|
||||
$money = new Money('999.23');
|
||||
self::assertEquals(9992300, $money->serialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The string character input is correctly unserialized from a numeric representation
|
||||
*/
|
||||
public function testMoneyUnserialization() : void
|
||||
{
|
||||
$money = new Money('999.23');
|
||||
$money->unserialize(3331234);
|
||||
self::assertEquals('333.12', $money->getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datatype correctly adds and subtracts the different money representations in string, numeric or Money type
|
||||
*/
|
||||
public function testMoneyAddSub() : void
|
||||
{
|
||||
$money = new Money(10000);
|
||||
|
|
@ -81,6 +125,9 @@ class MoneyTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals('1.0000', $money->sub(new Money(10000))->getAmount(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datatype correctly multiplies and devides the money with numerics
|
||||
*/
|
||||
public function testMoneyMultDiv() : void
|
||||
{
|
||||
$money = new Money(19100);
|
||||
|
|
@ -89,11 +136,21 @@ class MoneyTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals('1.9100', $money->div(2.0)->getAmount(4));
|
||||
}
|
||||
|
||||
public function testMoneyOtherOperations() : void
|
||||
/**
|
||||
* @testdox The datatype correctly handles the absolute value
|
||||
*/
|
||||
public function testMoneyAbsoluteValue() : void
|
||||
{
|
||||
$money = new Money(-38200);
|
||||
|
||||
self::assertEquals('3.8200', $money->mult(-1)->abs()->getAmount(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datatype correctly handles the power opperator
|
||||
*/
|
||||
public function testMoneyPower() : void
|
||||
{
|
||||
$money = new Money(-38200);
|
||||
self::assertEquals('800.0000', $money->setInt(200)->pow(3)->getAmount(4));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-clover" target="../build/logs/clover.xml"/>
|
||||
<log type="testdox-text" target="../Build/test/testdox_phpOMS.txt"/>
|
||||
<log type="coverage-clover" target="../Build/test/clover_phpOMS.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user