Passed
Push — master ( ad69c3...d9b15d )
by Jan
04:17
created

NodesListBuilderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testTypeToNodesListtRoot() 0 14 1
A testTypeToNodesListElement() 0 11 1
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\Services\Trees;
23
24
use App\Entity\Attachments\AttachmentType;
25
use App\Services\Trees\NodesListBuilder;
26
use Doctrine\ORM\EntityManagerInterface;
27
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
28
29
/**
30
 * @Group DB
31
 * @package App\Tests\Services\Trees
32
 */
33
class NodesListBuilderTest extends WebTestCase
34
{
35
36
    /**
37
     * @var NodesListBuilder $service
38
     */
39
    protected $service;
40
    protected $em;
41
42
    public function setUp(): void
43
    {
44
        self::bootKernel();
45
        $this->service = self::$container->get(NodesListBuilder::class);
46
        $this->em = self::$container->get(EntityManagerInterface::class);
47
    }
48
49
    /**
50
     * Test $repo->toNodesList() for null as parameter
51
     */
52
    public function testTypeToNodesListtRoot() : void
53
    {
54
        //List all root nodes and their children
55
        $nodes = $this->service->typeToNodesList(AttachmentType::class);
56
57
        $this->assertCount(7, $nodes);
58
        $this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes);
59
        $this->assertEquals('Node 1', $nodes[0]->getName());
60
        $this->assertEquals('Node 1.1', $nodes[1]->getName());
61
        $this->assertEquals('Node 1.1.1', $nodes[2]->getName());
62
        $this->assertEquals('Node 1.2', $nodes[3]->getName());
63
        $this->assertEquals('Node 2', $nodes[4]->getName());
64
        $this->assertEquals('Node 2.1', $nodes[5]->getName());
65
        $this->assertEquals('Node 3', $nodes[6]->getName());
66
    }
67
68
    public function testTypeToNodesListElement() : void
69
    {
70
        //List all nodes that are children to Node 1
71
        $node1 = $this->em->find(AttachmentType::class, 1);
72
        $nodes = $this->service->typeToNodesList(AttachmentType::class, $node1);
73
74
        $this->assertCount(3, $nodes);
75
        $this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes);
76
        $this->assertEquals('Node 1.1', $nodes[0]->getName());
77
        $this->assertEquals('Node 1.1.1', $nodes[1]->getName());
78
        $this->assertEquals('Node 1.2', $nodes[2]->getName());
79
    }
80
}
81