|
9 | 9 |
|
10 | 10 | use PHPUnit\Framework\TestCase; |
11 | 11 | use PhpValueObject\Person\Exception\WeightNotValidException; |
| 12 | +use PhpValueObject\Person\Grams; |
| 13 | +use PhpValueObject\Person\Kilograms; |
| 14 | +use PhpValueObject\Person\Pounds; |
12 | 15 | use PhpValueObject\Person\Weight; |
13 | 16 |
|
14 | 17 | class WeightTest extends TestCase |
15 | 18 | { |
16 | | - public function testWeightNotValidExceptionIsThrown() |
| 19 | + public function testPoundsIsBuild() |
17 | 20 | { |
18 | | - $this->expectException(WeightNotValidException::class); |
| 21 | + $pounds = 4.5; |
| 22 | + $poundsInstance = Pounds::fromPounds($pounds); |
| 23 | + $this->assertEquals($pounds, $poundsInstance->weight()); |
| 24 | + $this->assertEquals(Grams::fromGrams(2041.164), $poundsInstance->toGrams()); |
| 25 | + $this->assertEquals(Kilograms::fromKg(2.041164), $poundsInstance->toKilograms()); |
| 26 | + $this->assertEquals(Pounds::fromPounds($pounds), $poundsInstance->toPounds()); |
| 27 | + } |
19 | 28 |
|
20 | | - Weight::fromKg(2.34); |
| 29 | + public function testKilogramsIsBuild() |
| 30 | + { |
| 31 | + $kg = 87.7; |
| 32 | + $kilograms = Kilograms::fromKg($kg); |
| 33 | + $this->assertEquals($kg, $kilograms->weight()); |
| 34 | + $this->assertEquals(Grams::fromGrams($kg * 1000), $kilograms->toGrams()); |
| 35 | + $this->assertEquals(Pounds::fromPounds(193.34342), $kilograms->toPounds()); |
| 36 | + $this->assertEquals(Kilograms::fromKg($kg), $kilograms->toKilograms()); |
21 | 37 | } |
22 | 38 |
|
23 | | - public function testWeightIsValidInstance() |
| 39 | + public function testNotValidKilogramsException() |
24 | 40 | { |
25 | | - $weightInKg = 90.5; |
26 | | - $weightInPounds = $weightInKg * 2.2046; |
27 | | - $weight = Weight::fromKg($weightInKg); |
28 | | - $this->assertEquals($weightInKg, $weight->inKilograms()); |
29 | | - $this->assertEquals($weightInKg * 1000, $weight->inGrams()); |
30 | | - $this->assertEquals($weightInPounds, $weight->inPounds()); |
| 41 | + $this->expectException(WeightNotValidException::class); |
| 42 | + Kilograms::fromKg(-4.1); |
| 43 | + } |
| 44 | + |
| 45 | + public function testGramsIsBuild() |
| 46 | + { |
| 47 | + $grams = 87700; |
| 48 | + $grms = Grams::fromGrams($grams); |
| 49 | + $this->assertEquals(Kilograms::fromKg(87.7), $grms->toKilograms()); |
| 50 | + $this->assertEquals(Pounds::fromPounds(192.94), $grms->toPounds()); |
| 51 | + $this->assertEquals(Grams::fromGrams($grams), $grms->toGrams()); |
31 | 52 | } |
32 | 53 |
|
33 | 54 | /** |
34 | 55 | * @dataProvider weights |
35 | 56 | * @param Weight $weight |
36 | | - * @param Weight $otherWeight |
| 57 | + * @param Weight $weightToCompare |
37 | 58 | * @param bool $isEquals |
38 | 59 | */ |
39 | | - public function testEqualsMethod(Weight $weight, Weight $otherWeight, bool $isEquals) |
| 60 | + public function testEqualsMethod(Weight $weight, Weight $weightToCompare, bool $isEquals) |
40 | 61 | { |
41 | | - $this->assertEquals($weight->equals($otherWeight), $isEquals); |
| 62 | + $this->assertEquals($isEquals, $weight->equals($weightToCompare)); |
42 | 63 | } |
43 | 64 |
|
44 | | - /** |
45 | | - * @return array |
46 | | - */ |
47 | | - public function weights(): array |
| 65 | + public function weights() |
48 | 66 | { |
49 | 67 | return [ |
50 | | - [Weight::fromKg(25.98), Weight::fromKg(23.2), false], |
51 | | - [Weight::fromKg(25.98), Weight::fromKg(25.98), true] |
| 68 | + [Grams::fromGrams(123), Grams::fromGrams(123), true], |
| 69 | + [Grams::fromGrams(111), Grams::fromGrams(123), false] |
52 | 70 | ]; |
53 | 71 | } |
54 | 72 | } |
0 commit comments