| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Tests\Core; |
| 6 |
|
| 7 |
use InvalidArgumentException; |
| 8 |
use Packetery\Core\Rounder; |
| 9 |
use PHPUnit\Framework\TestCase; |
| 10 |
|
| 11 |
class RounderTest extends TestCase { |
| 12 |
public function testStatic(): void { |
| 13 |
$testValue = 106.5; |
| 14 |
|
| 15 |
self::assertSame( 106.0, Rounder::roundDown( $testValue ) ); |
| 16 |
self::assertSame( 107.0, Rounder::roundUp( $testValue ) ); |
| 17 |
self::assertSame( 110.0, Rounder::roundByCurrency( $testValue, 'HUF', Rounder::ROUND_UP ) ); |
| 18 |
self::assertSame( 107.0, Rounder::roundByCurrency( $testValue, 'CZK', Rounder::ROUND_UP ) ); |
| 19 |
self::assertSame( 106.5, Rounder::roundByCurrency( $testValue, 'EUR', Rounder::DONT_ROUND ) ); |
| 20 |
} |
| 21 |
|
| 22 |
public function testPrecisionException(): void { |
| 23 |
$this->expectException( InvalidArgumentException::class ); |
| 24 |
|
| 25 |
Rounder::round( 106.5, Rounder::DONT_ROUND, - 1 ); |
| 26 |
} |
| 27 |
|
| 28 |
public function testDivisorException(): void { |
| 29 |
$this->expectException( InvalidArgumentException::class ); |
| 30 |
|
| 31 |
Rounder::roundToMultipleOfNumber( 106.5, Rounder::DONT_ROUND, - 1 ); |
| 32 |
} |
| 33 |
|
| 34 |
public function testRoundingTypeException(): void { |
| 35 |
$this->expectException( InvalidArgumentException::class ); |
| 36 |
|
| 37 |
Rounder::roundByCurrency( 106.5, 'EUR', 2 ); |
| 38 |
} |
| 39 |
} |
| 40 |
|