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\Repository; |
23
|
|
|
|
24
|
|
|
use App\Entity\Attachments\AttachmentType; |
25
|
|
|
use App\Helpers\TreeViewNode; |
26
|
|
|
use App\Repository\StructuralDBElementRepository; |
27
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
28
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Group DB |
32
|
|
|
*/ |
33
|
|
|
class StructuralDBElementRepositoryTest extends WebTestCase |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
private $entityManager; |
37
|
|
|
/** @var StructuralDBElementRepository */ |
38
|
|
|
private $repo; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritDoc} |
42
|
|
|
*/ |
43
|
|
|
protected function setUp() : void |
44
|
|
|
{ |
45
|
|
|
$kernel = self::bootKernel(); |
46
|
|
|
|
47
|
|
|
$this->entityManager = $kernel->getContainer() |
48
|
|
|
->get('doctrine') |
49
|
|
|
->getManager(); |
50
|
|
|
|
51
|
|
|
$this->repo = $this->entityManager->getRepository(AttachmentType::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testFindRootNodes() : void |
55
|
|
|
{ |
56
|
|
|
$root_nodes = $this->repo->findRootNodes(); |
57
|
|
|
$this->assertCount(3, $root_nodes); |
58
|
|
|
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $root_nodes); |
59
|
|
|
|
60
|
|
|
//Asc sorting |
61
|
|
|
$this->assertEquals('Node 1', $root_nodes[0]->getName()); |
62
|
|
|
$this->assertEquals('Node 2', $root_nodes[1]->getName()); |
63
|
|
|
$this->assertEquals('Node 3', $root_nodes[2]->getName()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetGenericTree() : void |
67
|
|
|
{ |
68
|
|
|
$tree = $this->repo->getGenericNodeTree(); |
69
|
|
|
$this->assertIsArray($tree); |
70
|
|
|
$this->assertContainsOnlyInstancesOf(TreeViewNode::class, $tree); |
71
|
|
|
|
72
|
|
|
$this->assertCount(3, $tree); |
73
|
|
|
$this->assertCount(2, $tree[0]->getNodes()); |
74
|
|
|
$this->assertCount(1, $tree[0]->getNodes()[0]->getNodes()); |
75
|
|
|
$this->assertEmpty($tree[2]->getNodes()); |
76
|
|
|
$this->assertEmpty($tree[1]->getNodes()[0]->getNodes()); |
77
|
|
|
|
78
|
|
|
//Check text |
79
|
|
|
$this->assertEquals('Node 1', $tree[0]->getText()); |
80
|
|
|
$this->assertEquals('Node 2', $tree[1]->getText()); |
81
|
|
|
$this->assertEquals('Node 3', $tree[2]->getText()); |
82
|
|
|
$this->assertEquals('Node 1.1', $tree[0]->getNodes()[0]->getText()); |
83
|
|
|
$this->assertEquals('Node 1.1.1', $tree[0]->getNodes()[0]->getNodes()[0]->getText()); |
84
|
|
|
|
85
|
|
|
//Check that IDs were set correctly |
86
|
|
|
$this->assertEquals(1, $tree[0]->getId()); |
87
|
|
|
$this->assertEquals(2, $tree[1]->getId()); |
88
|
|
|
$this->assertEquals(7, $tree[0]->getNodes()[0]->getNodes()[0]->getId()); |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Test $repo->toNodesList() for null as parameter |
94
|
|
|
*/ |
95
|
|
|
public function testToNodesListRoot() : void |
96
|
|
|
{ |
97
|
|
|
//List all root nodes and their children |
98
|
|
|
$nodes = $this->repo->toNodesList(); |
99
|
|
|
|
100
|
|
|
$this->assertCount(7, $nodes); |
101
|
|
|
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes); |
102
|
|
|
$this->assertEquals('Node 1', $nodes[0]->getName()); |
103
|
|
|
$this->assertEquals('Node 1.1', $nodes[1]->getName()); |
104
|
|
|
$this->assertEquals('Node 1.1.1', $nodes[2]->getName()); |
105
|
|
|
$this->assertEquals('Node 1.2', $nodes[3]->getName()); |
106
|
|
|
$this->assertEquals('Node 2', $nodes[4]->getName()); |
107
|
|
|
$this->assertEquals('Node 2.1', $nodes[5]->getName()); |
108
|
|
|
$this->assertEquals('Node 3', $nodes[6]->getName()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testToNodesListElement() : void |
112
|
|
|
{ |
113
|
|
|
//List all nodes that are children to Node 1 |
114
|
|
|
$node1 = $this->repo->find(1); |
115
|
|
|
$nodes = $this->repo->toNodesList($node1); |
116
|
|
|
|
117
|
|
|
$this->assertCount(3, $nodes); |
118
|
|
|
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes); |
119
|
|
|
$this->assertEquals('Node 1.1', $nodes[0]->getName()); |
120
|
|
|
$this->assertEquals('Node 1.1.1', $nodes[1]->getName()); |
121
|
|
|
$this->assertEquals('Node 1.2', $nodes[2]->getName()); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
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