Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit ab7d0a7

Browse files
committed
Simplified tests
1 parent c5491f6 commit ab7d0a7

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

src/Decimal.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ public static function fromFloat($fltValue, $scale = null)
156156
}
157157

158158
return new Decimal(
159-
number_format($fltValue, $scale === null ? 8 : $scale, '.', ''),
159+
number_format(
160+
$fltValue,
161+
$scale === null ? 8 : $scale,
162+
'.',
163+
''
164+
),
160165
$scale === null ? 8 : $scale
161166
);
162167
}

tests/Decimal/DecimalInternalValidationTest.php

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,41 @@
88

99
class DecimalInternalValidationTest extends PHPUnit_Framework_TestCase
1010
{
11-
public function testInternalConstructorValidation()
11+
/**
12+
* @expectedException \InvalidArgumentException
13+
* @expectedExceptionMessage $value must be a non null number
14+
*/
15+
public function testConstructorNullValueValidation()
1216
{
13-
$thrown = false;
14-
try {
15-
$d = Decimal::fromInteger(null);
16-
} catch (InvalidArgumentException $e) {
17-
$thrown = true;
18-
}
19-
$this->assertTrue($thrown);
20-
21-
$thrown = false;
22-
try {
23-
$d = Decimal::fromInteger(25, -15);
24-
} catch (InvalidArgumentException $e) {
25-
$thrown = true;
26-
}
27-
$this->assertTrue($thrown);
28-
29-
$thrown = false;
30-
try {
31-
$d = Decimal::fromInteger(25, "hola mundo");
32-
} catch (InvalidArgumentException $e) {
33-
$thrown = true;
34-
}
35-
$this->assertTrue($thrown);
17+
Decimal::fromInteger(null);
3618
}
3719

38-
public function testInternalOperatorValidation()
20+
/**
21+
* @expectedException \InvalidArgumentException
22+
* @expectedExceptionMessage $scale must be a positive integer
23+
*/
24+
public function testConstructorNegativeScaleValidation()
25+
{
26+
Decimal::fromInteger(25, -15);
27+
}
28+
29+
/**
30+
* @expectedException \InvalidArgumentException
31+
* @expectedExceptionMessage $scale must be a positive integer
32+
*/
33+
public function testConstructorNotIntegerScaleValidation()
34+
{
35+
Decimal::fromInteger(25, "hola mundo");
36+
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage $scale must be a positive integer
41+
*/
42+
public function testOperatorNegativeScaleValidation()
3943
{
4044
$one = Decimal::fromInteger(1);
4145

42-
$thrown = false;
43-
try {
44-
$d = $one->mul($one, -1);
45-
} catch (InvalidArgumentException $e) {
46-
$thrown = true;
47-
}
48-
$this->assertTrue($thrown);
46+
$one->mul($one, -1);
4947
}
5048
}

0 commit comments

Comments
 (0)