PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / tests / Core / RounderTest.php

RounderTest.php in Packeta 2.1, at tests/Core/RounderTest.php

40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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