1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
25
|
|
|
* |
26
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
27
|
|
|
* |
28
|
|
|
* This program is free software: you can redistribute it and/or modify |
29
|
|
|
* it under the terms of the GNU Affero General Public License as published |
30
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
31
|
|
|
* (at your option) any later version. |
32
|
|
|
* |
33
|
|
|
* This program is distributed in the hope that it will be useful, |
34
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
35
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
36
|
|
|
* GNU Affero General Public License for more details. |
37
|
|
|
* |
38
|
|
|
* You should have received a copy of the GNU Affero General Public License |
39
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
namespace App\Tests\Entity\LogSystem; |
43
|
|
|
|
44
|
|
|
use App\Entity\Attachments\Attachment; |
45
|
|
|
use App\Entity\Attachments\AttachmentType; |
46
|
|
|
use App\Entity\Attachments\PartAttachment; |
47
|
|
|
use App\Entity\ProjectSystem\Project; |
48
|
|
|
use App\Entity\ProjectSystem\ProjectBOMEntry; |
49
|
|
|
use App\Entity\LogSystem\AbstractLogEntry; |
50
|
|
|
use App\Entity\Parts\Category; |
51
|
|
|
use App\Entity\Parts\Footprint; |
52
|
|
|
use App\Entity\Parts\Manufacturer; |
53
|
|
|
use App\Entity\Parts\Part; |
54
|
|
|
use App\Entity\Parts\Storelocation; |
55
|
|
|
use App\Entity\Parts\Supplier; |
56
|
|
|
use App\Entity\UserSystem\Group; |
57
|
|
|
use App\Entity\UserSystem\User; |
58
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
59
|
|
|
|
60
|
|
|
class AbstractLogEntryTest extends TestCase |
61
|
|
|
{ |
62
|
|
|
public function levelDataProvider(): array |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
[0, 'emergency'], |
66
|
|
|
[1, 'alert'], |
67
|
|
|
[2, 'critical'], |
68
|
|
|
[3, 'error'], |
69
|
|
|
[4, 'warning'], |
70
|
|
|
[5, 'notice'], |
71
|
|
|
[6, 'info'], |
72
|
|
|
[7, 'debug'], |
73
|
|
|
[8, 'blabla', true], |
74
|
|
|
[-1, 'test', true], |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function targetTypeDataProvider(): array |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
|
|
[1, User::class], |
82
|
|
|
[2, Attachment::class], |
83
|
|
|
[3, AttachmentType::class], |
84
|
|
|
[4, Category::class], |
85
|
|
|
[5, Project::class], |
86
|
|
|
[6, ProjectBOMEntry::class], |
87
|
|
|
[7, Footprint::class], |
88
|
|
|
[8, Group::class], |
89
|
|
|
[9, Manufacturer::class], |
90
|
|
|
[10, Part::class], |
91
|
|
|
[11, Storelocation::class], |
92
|
|
|
[12, Supplier::class], |
93
|
|
|
[-1, 'blablub', true], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @dataProvider levelDataProvider |
99
|
|
|
*/ |
100
|
|
|
public function testLevelIntToString(int $int, string $expected_string, bool $expect_exception = false): void |
101
|
|
|
{ |
102
|
|
|
if ($expect_exception) { |
103
|
|
|
$this->expectException(\InvalidArgumentException::class); |
104
|
|
|
} |
105
|
|
|
$this->assertSame($expected_string, AbstractLogEntry::levelIntToString($int)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @dataProvider levelDataProvider |
110
|
|
|
*/ |
111
|
|
|
public function testLevelStringToInt(int $expected_int, string $string, bool $expect_exception = false): void |
112
|
|
|
{ |
113
|
|
|
if ($expect_exception) { |
114
|
|
|
$this->expectException(\InvalidArgumentException::class); |
115
|
|
|
} |
116
|
|
|
$this->assertSame($expected_int, AbstractLogEntry::levelStringToInt($string)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @dataProvider targetTypeDataProvider |
121
|
|
|
*/ |
122
|
|
|
public function testTargetTypeIdToClass(int $int, string $expected_class, bool $expect_exception = false): void |
123
|
|
|
{ |
124
|
|
|
if ($expect_exception) { |
125
|
|
|
$this->expectException(\InvalidArgumentException::class); |
126
|
|
|
} |
127
|
|
|
$this->assertSame($expected_class, AbstractLogEntry::targetTypeIdToClass($int)); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @dataProvider targetTypeDataProvider |
132
|
|
|
*/ |
133
|
|
|
public function testTypeClassToID(int $expected_id, string $class, bool $expect_exception = false): void |
134
|
|
|
{ |
135
|
|
|
if ($expect_exception) { |
136
|
|
|
$this->expectException(\InvalidArgumentException::class); |
137
|
|
|
} |
138
|
|
|
$this->assertSame($expected_id, AbstractLogEntry::targetTypeClassToID($class)); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testTypeClassToIDSubclasses(): void |
142
|
|
|
{ |
143
|
|
|
//Test if class mapping works for subclasses |
144
|
|
|
$this->assertSame(2, AbstractLogEntry::targetTypeClassToID(PartAttachment::class)); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testSetGetTarget(): void |
148
|
|
|
{ |
149
|
|
|
$part = $this->createMock(Part::class); |
150
|
|
|
$part->method('getID')->willReturn(10); |
151
|
|
|
|
152
|
|
|
$log = new class() extends AbstractLogEntry { |
153
|
|
|
}; |
154
|
|
|
$log->setTargetElement($part); |
155
|
|
|
|
156
|
|
|
$this->assertSame(Part::class, $log->getTargetClass()); |
157
|
|
|
$this->assertSame(10, $log->getTargetID()); |
158
|
|
|
|
159
|
|
|
$log->setTargetElement(null); |
160
|
|
|
$this->assertNull($log->getTargetClass()); |
161
|
|
|
$this->assertNull($log->getTargetID()); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths