1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 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; |
23
|
|
|
|
24
|
|
|
use App\Entity\Attachments\AttachmentType; |
25
|
|
|
use App\Entity\Parts\Category; |
26
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
27
|
|
|
use Symfony\Component\Yaml\Tests\A; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test StructuralDBElement entities. |
31
|
|
|
* Note: Because StructuralDBElement is abstract we use AttachmentType here as a placeholder. |
32
|
|
|
*/ |
33
|
|
|
class StructuralDBElementTest extends TestCase |
34
|
|
|
{ |
35
|
|
|
protected $root; |
36
|
|
|
protected $child1; |
37
|
|
|
protected $child2; |
38
|
|
|
protected $child3; |
39
|
|
|
protected $child1_1; |
40
|
|
|
protected $child1_2; |
41
|
|
|
|
42
|
|
|
public function setUp() |
43
|
|
|
{ |
44
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
45
|
|
|
|
46
|
|
|
//Build a simple hierachy |
47
|
|
|
$this->root = new AttachmentType(); |
48
|
|
|
$this->root->setName('root')->setParent(null); |
49
|
|
|
$this->child1 = new AttachmentType(); |
50
|
|
|
$this->child1->setParent($this->root)->setName('child1'); |
51
|
|
|
$this->child2 = new AttachmentType(); |
52
|
|
|
$this->child2->setName('child2')->setParent($this->root); |
53
|
|
|
$this->child3 = new AttachmentType(); |
54
|
|
|
$this->child3->setName('child3')->setParent($this->root); |
55
|
|
|
$this->child1_1 = new AttachmentType(); |
56
|
|
|
$this->child1_1->setName('child1_1')->setParent($this->child1); |
57
|
|
|
$this->child1_2 = new AttachmentType(); |
58
|
|
|
$this->child1_2->setName('child1_2')->setParent($this->child1); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testIsRoot() |
62
|
|
|
{ |
63
|
|
|
$this->assertTrue($this->root->isRoot()); |
64
|
|
|
$this->assertFalse($this->child1->isRoot()); |
65
|
|
|
$this->assertFalse($this->child1_2->isRoot()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testIsChildOf() |
69
|
|
|
{ |
70
|
|
|
//Root must not be the child of any other node |
71
|
|
|
$this->assertFalse($this->root->isChildOf($this->child1)); |
72
|
|
|
$this->assertFalse($this->root->isChildOf($this->root)); |
73
|
|
|
|
74
|
|
|
//Check for direct parents |
75
|
|
|
$this->assertTrue($this->child1->isChildOf($this->root)); |
76
|
|
|
$this->assertTrue($this->child1_2->isChildOf($this->child1)); |
77
|
|
|
|
78
|
|
|
//Check for inheritance |
79
|
|
|
$this->assertTrue($this->child1_2->isChildOf($this->root)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testChildOfDifferentClasses() |
83
|
|
|
{ |
84
|
|
|
$this->expectException(\InvalidArgumentException::class); |
85
|
|
|
$category = new Category(); |
86
|
|
|
$this->root->isChildOf($category); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testChildOfExtendedClass() |
90
|
|
|
{ |
91
|
|
|
//Doctrine extends the entities for proxy classes so the isChildOf mus also work for inheritance types |
92
|
|
|
$inheritance = new class() extends AttachmentType { |
93
|
|
|
}; |
94
|
|
|
$inheritance->setParent($this->root); |
95
|
|
|
$this->assertTrue($inheritance->isChildOf($this->root)); |
96
|
|
|
$this->assertFalse($this->root->isChildOf($inheritance)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testGetLevel() |
100
|
|
|
{ |
101
|
|
|
$this->assertEquals(0, $this->root->getLevel()); |
102
|
|
|
$this->assertEquals(1, $this->child1->getLevel()); |
103
|
|
|
$this->assertSame(1, $this->child2->getLevel()); |
104
|
|
|
$this->assertSame(2, $this->child1_2->getLevel()); |
105
|
|
|
$this->assertSame(2, $this->child1_1->getLevel()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testGetFullPath() |
109
|
|
|
{ |
110
|
|
|
$this->assertSame('root/child1/child1_1', $this->child1_1->getFullPath('/')); |
111
|
|
|
$this->assertSame('root#child2', $this->child2->getFullPath('#')); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetPathArray() |
115
|
|
|
{ |
116
|
|
|
$this->assertEquals([$this->root, $this->child1, $this->child1_1], $this->child1_1->getPathArray()); |
117
|
|
|
$this->assertEquals([$this->root, $this->child1], $this->child1->getPathArray()); |
118
|
|
|
$this->assertEquals([$this->root], $this->root->getPathArray()); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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