| | +<?php |
| | +require_once '../Money.php'; |
| | +require_once '../Currency.php'; |
| | + |
| | +class MoneyTest { |
| | + /** |
| | + * Executes all test methods via callback. |
| | + * |
| | + * @param callable $callback Function to execute test methods |
| | + */ |
| | + public function run( $callback ) { |
| | + $callback( [ |
| | + 'test_Constructor_NegativeAmount_CreatesInstance', |
| | + 'test_Constructor_ZeroAmount_CreatesInstance', |
| | + 'test_Constructor_LargeAmount_CreatesInstance', |
| | + 'test_Constructor_ManyDecimals_CreatesInstance', |
| | + 'test_IsCurrency_MatchingCurrency_ReturnsTrue', |
| | + 'test_IsCurrency_DifferentCurrency_ReturnsFalse', |
| | + 'test_IsAmount_WithinTolerance_ReturnsTrue', |
| | + 'test_IsAmount_OutsideTolerance_ReturnsFalse' |
| | + ] ); |
| | + } |
| | + |
| | + public function test_Constructor_NegativeAmount_CreatesInstance() { |
| | + $money = new Money( -250.75, Currency::EUR ); |
| | + return $money->isAmount( -250.75 ) && $money->isCurrency( Currency::EUR ); |
| | + } |
| | + |
| | + public function test_Constructor_ZeroAmount_CreatesInstance() { |
| | + $money = new Money( 0.0, Currency::GBP ); |
| | + return $money->isAmount( 0.0 ) && $money->isCurrency( Currency::GBP ); |
| | + } |
| | + |
| | + public function test_Constructor_LargeAmount_CreatesInstance() { |
| | + $money = new Money( 999999999.99, Currency::CAD ); |
| | + return $money->isAmount( 999999999.99 ) && $money->isCurrency( Currency::CAD ); |
| | + } |
| | + |
| | + public function test_Constructor_ManyDecimals_CreatesInstance() { |
| | + $money = new Money( 123.456789, Currency::AUD ); |
| | + return $money->isAmount( 123.456789 ) && $money->isCurrency( Currency::AUD ); |
| | + } |
| | + |
| | + public function test_IsCurrency_MatchingCurrency_ReturnsTrue() { |
| | + $money = new Money( 50.0, Currency::USD ); |
| | + return $money->isCurrency( Currency::USD ); |
| | + } |
| | + |
| | + public function test_IsCurrency_DifferentCurrency_ReturnsFalse() { |
| | + $money = new Money( 50.0, Currency::USD ); |
| | + return !$money->isCurrency( Currency::EUR ); |
| | + } |
| | + |
| | + public function test_IsAmount_WithinTolerance_ReturnsTrue() { |
| | + $money = new Money( 100.005, Currency::USD ); |
| | + return $money->isAmount( 100.00 ); |
| | + } |
| | + |
| | + public function test_IsAmount_OutsideTolerance_ReturnsFalse() { |
| | + $money = new Money( 100.00, Currency::USD ); |
| | + return !$money->isAmount( 100.02 ); |
| | + } |
| | +} |
| | |