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\PagePartBundle\Tests\EventListener; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\Event\DeepCloneAndSaveEvent; |
||
6 | use Kunstmaan\PagePartBundle\Entity\PagePartRef; |
||
7 | use Kunstmaan\PagePartBundle\Entity\PageTemplateConfiguration; |
||
8 | use Kunstmaan\PagePartBundle\EventListener\CloneListener; |
||
9 | use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; |
||
10 | use Kunstmaan\PagePartBundle\Helper\HasPageTemplateInterface; |
||
11 | use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfigurator; |
||
12 | use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfiguratorInterface; |
||
13 | use Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationReaderInterface; |
||
14 | use Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationService; |
||
15 | use Kunstmaan\PagePartBundle\Repository\PagePartRefRepository; |
||
16 | use PHPUnit\Framework\TestCase; |
||
17 | |||
18 | /** |
||
19 | * Class CloneListenerTest |
||
20 | */ |
||
21 | class CloneListenerTest extends TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var \Doctrine\ORM\EntityManager|\PHPUnit_Framework_MockObject_MockObject |
||
25 | */ |
||
26 | private $em; |
||
27 | |||
28 | /** |
||
29 | * @var PagePartAdminConfiguratorInterface |
||
30 | */ |
||
31 | private $configurator; |
||
32 | |||
33 | /** |
||
34 | * @var \Doctrine\ORM\EntityRepository|\PHPUnit_Framework_MockObject_MockObject |
||
35 | */ |
||
36 | private $repo; |
||
37 | |||
38 | /** |
||
39 | * @var CloneListener |
||
40 | */ |
||
41 | private $object; |
||
42 | |||
43 | /** |
||
44 | * @var PagePartConfigurationReaderInterface|\PHPUnit_Framework_MockObject_MockObject |
||
45 | */ |
||
46 | private $reader; |
||
47 | |||
48 | /** |
||
49 | * @var PageTemplateConfigurationService|\PHPUnit_Framework_MockObject_MockObject |
||
50 | */ |
||
51 | private $templateService; |
||
52 | |||
53 | protected function setUp() |
||
54 | { |
||
55 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
||
56 | ->disableOriginalConstructor() |
||
57 | ->getMock(); |
||
58 | |||
59 | $this->repo = $this->getMockBuilder(PagePartRefRepository::class) |
||
60 | ->disableOriginalConstructor() |
||
61 | ->getMock(); |
||
62 | |||
63 | $this->em->expects($this->any()) |
||
64 | ->method('getRepository') |
||
65 | ->with($this->equalTo(PagePartRef::class)) |
||
66 | ->willReturn($this->repo); |
||
67 | |||
68 | $this->configurator = new PagePartAdminConfigurator(); |
||
69 | $this->configurator->setContext('main'); |
||
70 | |||
71 | $this->reader = $this->createMock(PagePartConfigurationReaderInterface::class); |
||
72 | $this->reader |
||
73 | ->expects($this->any()) |
||
74 | ->method('getPagePartAdminConfigurators') |
||
75 | ->willReturn([$this->configurator]); |
||
76 | |||
77 | $this->reader |
||
78 | ->expects($this->any()) |
||
79 | ->method('getPagePartContexts') |
||
80 | ->willReturn([$this->configurator->getContext()]); |
||
81 | |||
82 | $this->templateService = $this->getMockBuilder(PageTemplateConfigurationService::class)->disableOriginalConstructor()->getMock(); |
||
83 | |||
84 | $this->object = new CloneListener($this->em, $this->reader, $this->templateService); |
||
85 | } |
||
86 | |||
87 | View Code Duplication | public function testClonePagePart() |
|
88 | { |
||
89 | $entity = $this->createMock(HasPagePartsInterface::class); |
||
90 | |||
91 | $clone = clone $entity; |
||
92 | |||
93 | $this->repo->expects($this->once()) |
||
94 | ->method('copyPageParts') |
||
95 | ->with($this->em, $entity, $clone, 'main'); |
||
96 | |||
97 | $event = new DeepCloneAndSaveEvent($entity, $clone); |
||
98 | $this->object->postDeepCloneAndSave($event); |
||
99 | } |
||
100 | |||
101 | public function testClonePageTemplate() |
||
102 | { |
||
103 | $entity = $this->createMock(HasPageTemplateInterface::class); |
||
104 | |||
105 | /** @var HasPageTemplateInterface|\PHPUnit_Framework_MockObject_MockObject $clone */ |
||
106 | $clone = clone $entity; |
||
107 | |||
108 | $entity->expects($this->any()) |
||
109 | ->method('getId') |
||
110 | ->willReturn(1); |
||
111 | |||
112 | $clone->expects($this->any()) |
||
113 | ->method('getId') |
||
114 | ->willReturn(2); |
||
115 | |||
116 | $this->repo->expects($this->once()) |
||
117 | ->method('copyPageParts') |
||
118 | ->with($this->em, $entity, $clone, 'main'); |
||
119 | |||
120 | $configuration = new PageTemplateConfiguration(); |
||
121 | $configuration->setId(1); |
||
122 | $configuration->setPageId(1); |
||
123 | |||
124 | $this->templateService->expects($this->once()) |
||
0 ignored issues
–
show
|
|||
125 | ->method('findOrCreateFor') |
||
126 | ->with($this->identicalTo($entity)) |
||
127 | ->willReturn($configuration); |
||
128 | |||
129 | $newConfiguration = clone $configuration; |
||
130 | $newConfiguration->setId(null); |
||
131 | $newConfiguration->setPageId($clone->getId()); |
||
132 | |||
133 | $this->em->expects($this->once()) |
||
134 | ->method('persist') |
||
135 | ->with($newConfiguration); |
||
136 | |||
137 | $event = new DeepCloneAndSaveEvent($entity, $clone); |
||
138 | $this->object->postDeepCloneAndSave($event); |
||
139 | } |
||
140 | } |
||
141 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: