Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Tests/unit/EventListener/CloneListenerTest.php (5 issues)

Upgrade to new PHP Analysis Engine

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\PageTemplateConfiguration;
7
use Kunstmaan\PagePartBundle\EventListener\CloneListener;
8
use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface;
9
use Kunstmaan\PagePartBundle\Helper\HasPageTemplateInterface;
10
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfigurator;
11
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfiguratorInterface;
12
use Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationReaderInterface;
13
use Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationService;
14
use Kunstmaan\PagePartBundle\Repository\PagePartRefRepository;
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * Class CloneListenerTest
19
 */
20
class CloneListenerTest extends TestCase
21
{
22
    /**
23
     * @var \Doctrine\ORM\EntityManager|\PHPUnit_Framework_MockObject_MockObject
24
     */
25
    private $em;
26
27
    /**
28
     * @var PagePartAdminConfiguratorInterface
29
     */
30
    private $configurator;
31
32
    /**
33
     * @var \Doctrine\ORM\EntityRepository|\PHPUnit_Framework_MockObject_MockObject
34
     */
35
    private $repo;
36
37
    /**
38
     * @var CloneListener
39
     */
40
    private $object;
41
42
    /**
43
     * @var PagePartConfigurationReaderInterface|\PHPUnit_Framework_MockObject_MockObject
44
     */
45
    private $reader;
46
47
    /**
48
     * @var PageTemplateConfigurationService|\PHPUnit_Framework_MockObject_MockObject
49
     */
50
    private $templateService;
51
52
    protected function setUp()
53
    {
54
        $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
55
            ->disableOriginalConstructor()
56
            ->getMock();
57
58
        $this->repo = $this->getMockBuilder(PagePartRefRepository::class)
59
            ->disableOriginalConstructor()
60
            ->getMock();
61
62
        $this->em->expects($this->any())
63
            ->method('getRepository')
64
            ->with($this->equalTo('KunstmaanPagePartBundle:PagePartRef'))
65
            ->will($this->returnValue($this->repo));
66
67
        $this->configurator = new PagePartAdminConfigurator();
68
        $this->configurator->setContext('main');
69
70
        $this->reader = $this->createMock(PagePartConfigurationReaderInterface::class);
71
        $this->reader
72
            ->expects($this->any())
73
            ->method('getPagePartAdminConfigurators')
74
            ->will($this->returnValue([$this->configurator]));
75
76
        $this->reader
77
            ->expects($this->any())
78
            ->method('getPagePartContexts')
79
            ->will($this->returnValue([$this->configurator->getContext()]));
80
81
        $this->templateService = $this->getMockBuilder(PageTemplateConfigurationService::class)->disableOriginalConstructor()->getMock();
82
83
        $this->object = new CloneListener($this->em, $this->reader, $this->templateService);
84
    }
85
86 View Code Duplication
    public function testClonePagePart()
87
    {
88
        $entity = $this->createMock(HasPagePartsInterface::class);
89
90
        $clone = clone $entity;
91
92
        $this->repo->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityRepository.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
93
            ->method('copyPageParts')
94
            ->with($this->em, $entity, $clone, 'main');
95
96
        $event = new DeepCloneAndSaveEvent($entity, $clone);
97
        $this->object->postDeepCloneAndSave($event);
98
    }
99
100
    public function testClonePageTemplate()
101
    {
102
        $entity = $this->createMock(HasPageTemplateInterface::class);
103
104
        /** @var HasPageTemplateInterface|\PHPUnit_Framework_MockObject_MockObject $clone */
105
        $clone = clone $entity;
106
107
        $entity->expects($this->any())
108
            ->method('getId')
109
            ->will($this->returnValue(1));
110
111
        $clone->expects($this->any())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Kunstmaan\PagePartBundle...asPageTemplateInterface.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
            ->method('getId')
113
            ->will($this->returnValue(2));
114
115
        $this->repo->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityRepository.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
116
            ->method('copyPageParts')
117
            ->with($this->em, $entity, $clone, 'main');
118
119
        $configuration = new PageTemplateConfiguration();
120
        $configuration->setId(1);
121
        $configuration->setPageId(1);
122
123
        $this->templateService->expects($this->once())
124
            ->method('findOrCreateFor')
125
            ->with($this->identicalTo($entity))
126
            ->will($this->returnValue($configuration));
127
128
        $newConfiguration = clone $configuration;
129
        $newConfiguration->setId(null);
130
        $newConfiguration->setPageId($clone->getId());
0 ignored issues
show
The method getId does only exist in Kunstmaan\PagePartBundle...asPageTemplateInterface, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
131
132
        $this->em->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManager.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
133
            ->method('persist')
134
            ->with($newConfiguration);
135
136
        $event = new DeepCloneAndSaveEvent($entity, $clone);
137
        $this->object->postDeepCloneAndSave($event);
138
    }
139
}
140