IncomeCalculatorTest::calculateTaxSpec()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 19
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 25
rs 9.6333
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;
0 ignored issues
show
Bug Best Practice introduced by
The property tester does not exist on Tests\Unit\Example\IncomeCalculatorTest. Did you maybe forget to declare it?
Loading history...
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())
0 ignored issues
show
Unused Code introduced by
The call to PHPKitchen\CodeSpecs\Contract\TestGuy::seeNumber() has too many arguments starting with $service->calculateTax(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
            $I->/** @scrutinizer ignore-call */ 
45
                seeNumber('income tax', $service->calculateTax())

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
'income tax' of type string is incompatible with the type double|integer expected by parameter $variable of PHPKitchen\CodeSpecs\Contract\TestGuy::seeNumber(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            $I->seeNumber(/** @scrutinizer ignore-type */ 'income tax', $service->calculateTax())
Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The property tester does not exist on Tests\Unit\Example\IncomeCalculatorTest. Did you maybe forget to declare it?
Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter $workingHours is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    public function __construct($clientsPayments, /** @scrutinizer ignore-unused */ $workingHours) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $clientsPayments is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    public function __construct(/** @scrutinizer ignore-unused */ $clientsPayments, $workingHours) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
}