From af77f42eeb5a215ee6aa7635369919217c5d29e8 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 15 Apr 2019 20:00:28 +0200 Subject: [PATCH] Draft @testdox example --- tests/Localization/MoneyTest.php | 71 ++++++++++++++++++++++++++++---- tests/phpunit_no_coverage.xml | 3 +- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/tests/Localization/MoneyTest.php b/tests/Localization/MoneyTest.php index 0b0dcf205..c0b3ec114 100644 --- a/tests/Localization/MoneyTest.php +++ b/tests/Localization/MoneyTest.php @@ -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)); } } diff --git a/tests/phpunit_no_coverage.xml b/tests/phpunit_no_coverage.xml index e3c0b4736..195989747 100644 --- a/tests/phpunit_no_coverage.xml +++ b/tests/phpunit_no_coverage.xml @@ -33,6 +33,7 @@ - + +