This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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
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. ![]() |
|||
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
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. ![]() |
|||
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
$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 ![]() |
|||
77 | $this->assertFalse($year->checkYear(false)); |
||
78 | } |
||
79 | |||
80 | View Code Duplication | function testIsYearSetReturnsTrueWhenYearIsset() |
|
0 ignored issues
–
show
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. ![]() |
|||
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
$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 ![]() |
|||
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
$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 ![]() |
|||
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
$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 ![]() |
|||
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
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);
![]() |
|||
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 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: