Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

FolderManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 9.312
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\MediaBundle\Tests\Helper;
4
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Kunstmaan\MediaBundle\Entity\Folder;
7
use Kunstmaan\MediaBundle\Helper\FolderManager;
8
use PHPUnit\Framework\TestCase;
9
10
class FolderManagerTest extends TestCase
11
{
12
    /**
13
     * @var ObjectRepository
14
     */
15
    protected $repository;
16
17
    /**
18
     * @var Folder
19
     */
20
    protected $folder;
21
22
    /**
23
     * @var FolderManager
24
     */
25
    protected $object;
26
27
    /**
28
     * @var array
29
     */
30
    private $parents;
31
32
    protected function setUp()
33
    {
34
        $this->repository = $this->getMockBuilder('Kunstmaan\MediaBundle\Repository\FolderRepository')
0 ignored issues
show
Documentation Bug introduced by Wim Vandersmissen
It seems like $this->getMockBuilder('K...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\Common\P...tence\ObjectRepository> of property $repository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
            ->disableOriginalConstructor()
36
            ->getMock();
37
38
        $this->repository
39
            ->expects($this->any())
40
            ->method('getParentIds')
41
            ->willReturn([1, 2]);
42
43
        $folder1 = new Folder();
44
        $folder1->setId(1);
45
46
        $folder2 = new Folder();
47
        $folder2->setId(2);
48
49
        $this->parents = array($folder1, $folder2);
50
51
        $this->repository
52
            ->expects($this->any())
53
            ->method('getPath')
54
            ->willReturn(array($folder1, $folder2));
55
56
        $rootFolder = new Folder();
57
        $rootFolder->setId(1);
58
59
        $this->repository
60
            ->expects($this->any())
61
            ->method('getFolder')
62
            ->with($this->equalTo(1))
63
            ->willReturn($rootFolder);
64
65
        $this->folder = new Folder();
66
        $this->folder->setId(3);
67
68
        $this->object = new FolderManager($this->repository);
0 ignored issues
show
Documentation introduced by Wim Vandersmissen
$this->repository is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\MediaBu...itory\FolderRepository>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
    }
70
71
    public function testGetFolderHierarchy()
72
    {
73
        $this->repository
74
            ->expects($this->once())
75
            ->method('childrenHierarchy')
76
            ->with($this->equalTo($this->folder))
77
            ->willReturn(array());
78
79
        $this->object->getFolderHierarchy($this->folder);
80
    }
81
82
    public function testGetRootFolderFor()
83
    {
84
        $this->repository
85
            ->expects($this->once())
86
            ->method('getFolder')
87
            ->with($this->equalTo(1));
88
89
        $rootFolder = $this->object->getRootFolderFor($this->folder);
90
        $this->assertEquals(1, $rootFolder->getId());
91
    }
92
93 View Code Duplication
    public function testGetParentIds()
0 ignored issues
show
Duplication introduced by Wim Vandersmissen
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $this->repository
96
            ->expects($this->once())
97
            ->method('getParentIds')
98
            ->with($this->equalTo($this->folder));
99
100
        $this->assertEquals(array(1, 2), $this->object->getParentIds($this->folder));
101
    }
102
103 View Code Duplication
    public function testGetParents()
0 ignored issues
show
Duplication introduced by Wim Vandersmissen
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        $this->repository
106
            ->expects($this->once())
107
            ->method('getPath')
108
            ->with($this->equalTo($this->folder));
109
110
        $this->assertEquals($this->parents, $this->object->getParents($this->folder));
111
    }
112
}
113