1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit\Example; |
4
|
|
|
|
5
|
|
|
use PHPKitchen\CodeSpecs\Base\Specification; |
6
|
|
|
use PHPKitchen\CodeSpecs\Contract\TestGuy; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Specification of {@link IncomeCalculator} |
10
|
|
|
* |
11
|
|
|
* @author Dmitry Kolodko <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class IncomeCalculatorTest extends Specification { |
14
|
|
|
private const EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE = 4500; |
15
|
|
|
private const EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE = 7200; |
16
|
|
|
private const EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE = 30000; |
17
|
|
|
private const INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE = 300000; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
*/ |
22
|
|
|
public function calculateTaxSpec() { |
23
|
|
|
$clientsPayments = []; // dummy variable, just for example |
24
|
|
|
$hoursSpentWorking = 160; // dummy variable, just for example |
25
|
|
|
$service = new IncomeCalculator($clientsPayments, $hoursSpentWorking); |
26
|
|
|
$I = $this->tester; |
|
|
|
|
27
|
|
|
$I->describe('income tax calculations'); |
28
|
|
|
|
29
|
|
|
$I->verifyThat('income calculator honors tax rules for different ranges of income', function (TestGuy $I) use ($service) { |
30
|
|
|
$I->lookAt('income tax'); |
31
|
|
|
|
32
|
|
|
$I->expectThat('for income less that 50 000 calculator use 10% tax rule'); |
33
|
|
|
|
34
|
|
|
$I->seeNumber($service->calculateTax()) |
35
|
|
|
->isNotEmpty() |
36
|
|
|
->isEqualTo(self::EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE); |
37
|
|
|
|
38
|
|
|
$I->expectThat('for income between 50 000 and 100 000 calculator use 12% tax rule'); |
39
|
|
|
$I->seeNumber($service->calculateTax()) |
40
|
|
|
->isNotEmpty() |
41
|
|
|
->isEqualTo(self::EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE); |
42
|
|
|
|
43
|
|
|
$I->expectThat('for income more than 100 000 calculator use 20% tax rule'); |
44
|
|
|
$I->seeNumber('income tax', $service->calculateTax()) |
|
|
|
|
45
|
|
|
->isNotEmpty() |
46
|
|
|
->isEqualTo(self::EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE); |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function calculateWithTaxSpec() { |
54
|
|
|
$clientsPayments = []; // dummy variable, just for example |
55
|
|
|
$hoursSpentWorking = 160; // dummy variable, just for example |
56
|
|
|
$service = new IncomeCalculator($clientsPayments, $hoursSpentWorking); |
57
|
|
|
|
58
|
|
|
$I = $this->tester; |
|
|
|
|
59
|
|
|
$I->describe('income calculation'); |
60
|
|
|
|
61
|
|
|
$I->lookAt('income tax'); |
62
|
|
|
|
63
|
|
|
$I->expectThat('calculator calculates income with tax using 10% tax rule for income less that 50 000'); |
64
|
|
|
|
65
|
|
|
$I->seeNumber($service->calculateWithTax()) |
66
|
|
|
->isNotEmpty() |
67
|
|
|
->isEqualTo(self::INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
class IncomeCalculator { |
72
|
|
|
public function __construct($clientsPayments, $workingHours) { |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function calculateWithoutTax() { |
76
|
|
|
return 478; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function calculateWithTax() { |
80
|
|
|
return 478; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function calculateTax() { |
84
|
|
|
return 4500; |
85
|
|
|
} |
86
|
|
|
} |