YearTest::testIsYearSetReturnsTrueWhenYearIsset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
require_once 'Intraface/modules/accounting/Year.php';
3
require_once 'Intraface/functions.php';
4
5
class YearTest extends PHPUnit_Framework_TestCase
6
{
7
    function setUp()
8
    {
9
        $this->kernel = new Stub_Kernel();
0 ignored issues
show
Bug introduced by
The property kernel does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
10
        $this->kernel->setting->set('intranet', 'vatpercent', 25);
11
        $this->kernel->setting->set('user', 'accounting.active_year', 0);
12
        $this->kernel->setting->set('intranet', 'accounting.result_account_id', 25);
13
        $this->kernel->setting->set('intranet', 'accounting.debtor_account_id', 25);
14
        $this->kernel->setting->set('intranet', 'accounting.credit_account_id', 25);
15
        $this->kernel->setting->set('intranet', 'accounting.balance_accounts', serialize(array()));
16
        $this->kernel->setting->set('intranet', 'accounting.result_account_id_start', 0);
17
        $this->kernel->setting->set('intranet', 'accounting.result_account_id_end', 0);
18
        $this->kernel->setting->set('intranet', 'accounting.balance_account_id_start', 0);
19
        $this->kernel->setting->set('intranet', 'accounting.balance_account_id_end', 0);
20
        $this->kernel->setting->set('intranet', 'accounting.capital_account_id', 0);
21
22
        $this->kernel->setting->set('intranet', 'accounting.vat_in_account_id', 0);
23
        $this->kernel->setting->set('intranet', 'accounting.vat_out_account_id', 0);
24
        $this->kernel->setting->set('intranet', 'accounting.vat_abroad_account_id', 0);
25
        $this->kernel->setting->set('intranet', 'accounting.vat_balance_account_id', 0);
26
        $this->kernel->setting->set('intranet', 'accounting.vat_free_account_id', 0);
27
        $this->kernel->setting->set('intranet', 'accounting.eu_sale_account_id', 0);
28
        $this->kernel->setting->set('intranet', 'accounting.result_account_id', 0);
29
        $this->kernel->setting->set('intranet', 'accounting.debtor_account_id', 0);
30
        $this->kernel->setting->set('intranet', 'accounting.credit_account_id', 0);
31
        $this->kernel->setting->set('intranet', 'accounting.balance_accounts', serialize(array()));
32
        $this->kernel->setting->set('intranet', 'accounting.buy_eu_accounts', serialize(array()));
33
        $this->kernel->setting->set('intranet', 'accounting.buy_abroad_accounts', serialize(array()));
34
35
        $this->kernel->setting->set('intranet', 'accounting.result_account_id_start', 0);
36
        $this->kernel->setting->set('intranet', 'accounting.result_account_id_end', 0);
37
        $this->kernel->setting->set('intranet', 'accounting.balance_account_id_start', 0);
38
        $this->kernel->setting->set('intranet', 'accounting.balance_account_id_end', 0);
39
40
        $this->kernel->setting->set('intranet', 'accounting.capital_account_id', 0);
41
    }
42
43
    function tearDown()
44
    {
45
        $db = MDB2::singleton(DB_DSN);
46
        $db->exec('TRUNCATE accounting_year');
47
    }
48
49
    function testSetYearReturnsFalseWhenYearObjectIsNotSet()
50
    {
51
        $year = new Year($this->kernel);
52
        $this->assertFalse($year->setYear());
53
    }
54
55 View Code Duplication
    function testSetYearReturnsTrueWhenYearObjectIsSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $year = new Year($this->kernel);
58
        $id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
59
        $this->assertTrue($id > 0);
60
        $this->assertTrue($year->setYear());
61
        $this->assertEquals($id, $year->getActiveYear());
62
    }
63
64 View Code Duplication
    function testCheckYearReturnsTrueIfActiveYearIsset()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $year = new Year($this->kernel);
67
        $id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
68
        $this->assertTrue($id > 0);
69
        $this->assertTrue($year->setYear());
70
        $this->assertTrue($year->checkYear());
71
    }
72
73
    function testCheckYearReturnsFalseIfActiveYearIsNotset()
74
    {
75
        $year = new Year($this->kernel);
76
        $id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
        $this->assertFalse($year->checkYear(false));
78
    }
79
80 View Code Duplication
    function testIsYearSetReturnsTrueWhenYearIsset()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        $year = new Year($this->kernel);
83
        $id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
84
        $this->assertTrue($id > 0);
85
        $this->assertTrue($year->setYear());
86
        $this->assertTrue($year->isYearSet());
87
    }
88
89
    function testSaveMethod()
90
    {
91
        // TODO needs to be updated
92
        $year = new Year($this->kernel);
93
        $this->assertFalse($year->get('id') > 0);
94
        $this->assertTrue($year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)) > 0);
95
        $this->assertEquals('2000', $year->get('label'));
96
97
        $new_year = new Year($this->kernel, $year->get('id'), false);
98
        $this->assertTrue($new_year->save(array('label' => '2000 - edited', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)) > 0);
99
        $this->assertEquals($new_year->get('id'), $year->get('id'));
100
        $this->assertEquals($new_year->get('label'), '2000 - edited');
101
    }
102
103
    function testIsBalancedReturnsTrueWhenNoPostsHasBeenAdded()
104
    {
105
        $year = new Year($this->kernel);
106
        $id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
107
        $this->assertTrue($year->isBalanced());
108
    }
109
110
    function testGetList()
111
    {
112
        $year = new Year($this->kernel);
113
        $this->assertTrue(is_array($year->getList()));
114
    }
115
116
    function testGetBalanceAccountsThrowsEceptionIfBalanceAccountsIsNotAnArray()
117
    {
118
        $year = new Year($this->kernel);
119
        $id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
120
121
        try {
122
            $year->getBalanceAccounts();
123
            $this->assertTrue(false);
124
        } catch (Exception $e) {
125
            $this->assertTrue(true);
126
        }
127
    }
128
129
    function testCreateAccounts()
130
    {
131
        $year = new Year($this->kernel);
132
        $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
133
        $res = $year->createAccounts('standard');
134
        $this->assertTrue($res);
135
    }
136
137
    function testIsSettingsSet()
138
    {
139
        $year = new Year($this->kernel);
140
        $this->assertFalse($year->isSettingsSet());
141
    }
142
143
    function testGetSettings()
144
    {
145
        $year = new Year($this->kernel);
146
        $this->assertTrue(is_array($year->getSettings()));
147
    }
148
149
    function testSetSettings()
150
    {
151
        $year = new Year($this->kernel);
152
        $data = array();
153
        $this->assertTrue($year->setSettings($data));
154
    }
155
156
    function testReadyForState()
157
    {
158
        $year = new Year($this->kernel);
159
        $data = array();
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
160
        $this->assertFalse($year->readyForState());
161
    }
162
163
    function testIsYearOpen()
164
    {
165
        $year = new Year($this->kernel);
166
        $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
167
        $this->assertTrue($year->isYearOpen());
168
    }
169
170
    function testIsDateInYear()
171
    {
172
        $year = new Year($this->kernel);
173
        $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
174
        $this->assertFalse($year->isDateinYear(date('Y-m-d')));
0 ignored issues
show
Documentation introduced by
date('Y-m-d') is of type string, but the function expects a object<date>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
    }
176
177
    function testVatAccountIsSetReturnsTrueWhenVatOnYearIsNotSet()
178
    {
179
        $year = new Year($this->kernel);
180
        $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0));
181
        $this->assertTrue($year->vatAccountIsSet());
182
    }
183
}
184