These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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') |
||
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); |
||
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
|
|||
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
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 |
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.