|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or |
|
8
|
|
|
* modify it under the terms of the GNU General Public License |
|
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
10
|
|
|
* of the License, or (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 General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program; if not, write to the Free Software |
|
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace App\Tests\Entity\LogSystem; |
|
23
|
|
|
|
|
24
|
|
|
use App\Entity\Attachments\Attachment; |
|
25
|
|
|
use App\Entity\Attachments\AttachmentType; |
|
26
|
|
|
use App\Entity\Attachments\PartAttachment; |
|
27
|
|
|
use App\Entity\Devices\Device; |
|
28
|
|
|
use App\Entity\LogSystem\AbstractLogEntry; |
|
29
|
|
|
use App\Entity\Parts\Category; |
|
30
|
|
|
use App\Entity\Parts\Footprint; |
|
31
|
|
|
use App\Entity\Parts\Manufacturer; |
|
32
|
|
|
use App\Entity\Parts\Part; |
|
33
|
|
|
use App\Entity\Parts\Storelocation; |
|
34
|
|
|
use App\Entity\Parts\Supplier; |
|
35
|
|
|
use App\Entity\UserSystem\Group; |
|
36
|
|
|
use App\Entity\UserSystem\User; |
|
37
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
38
|
|
|
use App\Entity\Devices\DevicePart; |
|
39
|
|
|
|
|
40
|
|
|
class AbstractLogEntryTest extends TestCase |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
public function levelDataProvider(): array |
|
44
|
|
|
{ |
|
45
|
|
|
return [ |
|
46
|
|
|
[0, 'emergency'], |
|
47
|
|
|
[1, 'alert'], |
|
48
|
|
|
[2, 'critical'], |
|
49
|
|
|
[3, 'error'], |
|
50
|
|
|
[4, 'warning'], |
|
51
|
|
|
[5, 'notice'], |
|
52
|
|
|
[6, 'info'], |
|
53
|
|
|
[7, 'debug'], |
|
54
|
|
|
[8, 'blabla', true], |
|
55
|
|
|
[-1, 'test', true] |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function targetTypeDataProvider(): array |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
|
|
[1, User::class], |
|
63
|
|
|
[2, Attachment::class], |
|
64
|
|
|
[3, AttachmentType::class], |
|
65
|
|
|
[4, Category::class], |
|
66
|
|
|
[5, Device::class], |
|
67
|
|
|
[6, DevicePart::class], |
|
68
|
|
|
[7, Footprint::class], |
|
69
|
|
|
[8, Group::class], |
|
70
|
|
|
[9, Manufacturer::class], |
|
71
|
|
|
[10, Part::class], |
|
72
|
|
|
[11, Storelocation::class], |
|
73
|
|
|
[12, Supplier::class], |
|
74
|
|
|
[-1, 'blablub', true] |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @dataProvider levelDataProvider |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testLevelIntToString(int $int, string $expected_string, bool $expect_exception = false) |
|
82
|
|
|
{ |
|
83
|
|
|
if ($expect_exception) { |
|
84
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
85
|
|
|
} |
|
86
|
|
|
$this->assertSame($expected_string, AbstractLogEntry::levelIntToString($int)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @dataProvider levelDataProvider |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testLevelStringToInt(int $expected_int, string $string, bool $expect_exception = false) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($expect_exception) { |
|
95
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
96
|
|
|
} |
|
97
|
|
|
$this->assertSame($expected_int, AbstractLogEntry::levelStringToInt($string)); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @dataProvider targetTypeDataProvider |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testTargetTypeIdToClass(int $int, string $expected_class, bool $expect_exception = false) |
|
104
|
|
|
{ |
|
105
|
|
|
if ($expect_exception) { |
|
106
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
107
|
|
|
} |
|
108
|
|
|
$this->assertSame($expected_class, AbstractLogEntry::targetTypeIdToClass($int)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @dataProvider targetTypeDataProvider |
|
113
|
|
|
*/ |
|
114
|
|
|
public function testTypeClassToID(int $expected_id, string $class, bool $expect_exception = false) |
|
115
|
|
|
{ |
|
116
|
|
|
if ($expect_exception) { |
|
117
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
118
|
|
|
} |
|
119
|
|
|
$this->assertSame($expected_id, AbstractLogEntry::targetTypeClassToID($class)); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testTypeClassToIDSubclasses() |
|
123
|
|
|
{ |
|
124
|
|
|
//Test if class mapping works for subclasses |
|
125
|
|
|
$this->assertSame(2, AbstractLogEntry::targetTypeClassToID(PartAttachment::class)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testSetGetTarget() |
|
129
|
|
|
{ |
|
130
|
|
|
$part = $this->createMock(Part::class); |
|
131
|
|
|
$part->method('getID')->willReturn(10); |
|
132
|
|
|
|
|
133
|
|
|
$log = new class extends AbstractLogEntry {}; |
|
134
|
|
|
$log->setTargetElement($part); |
|
135
|
|
|
|
|
136
|
|
|
$this->assertSame(Part::class, $log->getTargetClass()); |
|
137
|
|
|
$this->assertSame(10, $log->getTargetID()); |
|
138
|
|
|
|
|
139
|
|
|
$log->setTargetElement(null); |
|
140
|
|
|
$this->assertSame(null, $log->getTargetClass()); |
|
141
|
|
|
$this->assertSame(null, $log->getTargetID()); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
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