/
PriceTest.php
63 lines (52 loc) · 1.33 KB
/
PriceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Simara\Cart\Domain;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
class PriceTest extends TestCase
{
public function testAdd()
{
$a = new Price("10.0");
$b = new Price("0.5");
$result = $a->add($b);
$expected = new Price("10.5");
Assert::assertEquals($expected, $result);
}
public function testMultiply()
{
$a = new Price("10.3");
$result = $a->multiply(2);
$expected = new Price("20.6");
Assert::assertEquals($expected, $result);
}
public function testSum()
{
$prices = [
new Price("9.0"),
new Price("0.7"),
new Price("0.3"),
];
$sum = Price::sum($prices);
$expected = new Price("10.0");
Assert::assertEquals($expected, $sum);
}
/**
* @dataProvider getterTestCases
*/
public function testGetter(string $converted, string $expected)
{
$price = new Price($converted);
$this->assertSame($expected, $price->getWithVat());
}
public function getterTestCases(): array
{
return [
["0.005", "0.00"],
["0.05" , "0.05"],
["0.5" , "0.50"],
["0" , "0.00"],
["5" , "5.00"],
["5.555", "5.55"],
];
}
}