-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIncomeCalculatorTest.php
More file actions
86 lines (68 loc) · 2.77 KB
/
Copy pathIncomeCalculatorTest.php
File metadata and controls
86 lines (68 loc) · 2.77 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Tests\Unit\Example;
use PHPKitchen\CodeSpecs\Base\Specification;
use PHPKitchen\CodeSpecs\Contract\TestGuy;
/**
* Specification of {@link IncomeCalculator}
*
* @author Dmitry Kolodko <prowwid@gmail.com>
*/
class IncomeCalculatorTest extends Specification {
private const EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE = 4500;
private const EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE = 7200;
private const EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE = 30000;
private const INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE = 300000;
/**
* @test
*/
public function calculateTaxSpec() {
$clientsPayments = []; // dummy variable, just for example
$hoursSpentWorking = 160; // dummy variable, just for example
$service = new IncomeCalculator($clientsPayments, $hoursSpentWorking);
$I = $this->tester;
$I->describe('income tax calculations');
$I->verifyThat('income calculator honors tax rules for different ranges of income', function (TestGuy $I) use ($service) {
$I->lookAt('income tax');
$I->expectThat('for income less that 50 000 calculator use 10% tax rule');
$I->seeNumber($service->calculateTax())
->isNotEmpty()
->isEqualTo(self::EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE);
$I->expectThat('for income between 50 000 and 100 000 calculator use 12% tax rule');
$I->seeNumber($service->calculateTax())
->isNotEmpty()
->isEqualTo(self::EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE);
$I->expectThat('for income more than 100 000 calculator use 20% tax rule');
$I->seeNumber('income tax', $service->calculateTax())
->isNotEmpty()
->isEqualTo(self::EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE);
});
}
/**
* @test
*/
public function calculateWithTaxSpec() {
$clientsPayments = []; // dummy variable, just for example
$hoursSpentWorking = 160; // dummy variable, just for example
$service = new IncomeCalculator($clientsPayments, $hoursSpentWorking);
$I = $this->tester;
$I->describe('income calculation');
$I->lookAt('income tax');
$I->expectThat('calculator calculates income with tax using 10% tax rule for income less that 50 000');
$I->seeNumber($service->calculateWithTax())
->isNotEmpty()
->isEqualTo(self::INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE);
}
}
class IncomeCalculator {
public function __construct($clientsPayments, $workingHours) {
}
public function calculateWithoutTax() {
return 478;
}
public function calculateWithTax() {
return 478;
}
public function calculateTax() {
return 4500;
}
}