Completed
Push — master ( 8be43b...f61101 )
by Eric
9s
created

ResourceSubscriberTest::createMappingExceptionMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\ResourceBundle\Tests\EventSubscriber\Doctrine\MongoDB;
13
14
use Doctrine\Common\EventSubscriber;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs;
17
use Doctrine\ODM\MongoDB\Events;
18
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
19
use Doctrine\ODM\MongoDB\Mapping\MappingException;
20
use Lug\Bundle\ResourceBundle\EventSubscriber\Doctrine\MongoDB\ResourceSubscriber;
21
use Lug\Component\Registry\Model\RegistryInterface;
22
use Lug\Component\Resource\Model\ResourceInterface;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class ResourceSubscriberTest extends \PHPUnit_Framework_TestCase
28
{
29
    /**
30
     * @var ResourceSubscriber
31
     */
32
    private $resourceSubscriber;
33
34
    /**
35
     * @var \PHPUnit_Framework_MockObject_MockObject|RegistryInterface
36
     */
37
    private $serviceRegistry;
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function setUp()
43
    {
44
        if (!class_exists(LoadClassMetadataEventArgs::class)) {
45
            $this->markTestSkipped();
46
        }
47
48
        $this->serviceRegistry = $this->createServiceRegistryMock();
49
        $this->resourceSubscriber = new ResourceSubscriber($this->serviceRegistry);
50
    }
51
52
    public function testInheritance()
53
    {
54
        $this->assertInstanceOf(EventSubscriber::class, $this->resourceSubscriber);
55
    }
56
57
    public function testSubscribedEvents()
58
    {
59
        $this->assertSame([Events::loadClassMetadata], $this->resourceSubscriber->getSubscribedEvents());
60
    }
61
62 View Code Duplication
    public function testLoadClassMetadataWithResourceAndNoParentClasses()
0 ignored issues
show
Duplication introduced by
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...
63
    {
64
        $event = $this->createLoadClassMetadataEventArgsMock();
65
        $event
66
            ->expects($this->once())
67
            ->method('getClassMetadata')
68
            ->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
69
70
        $classMetadata
71
            ->expects($this->once())
72
            ->method('getName')
73
            ->will($this->returnValue($model = 'model'));
74
75
        $this->serviceRegistry
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Registry\Model\RegistryInterface.

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...
76
            ->expects($this->once())
77
            ->method('getIterator')
78
            ->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
79
80
        $resource
81
            ->expects($this->once())
82
            ->method('getModel')
83
            ->will($this->returnValue($model));
84
85
        $resource
86
            ->expects($this->once())
87
            ->method('getRepository')
88
            ->will($this->returnValue($repository = 'repository'));
89
90
        $classMetadata
91
            ->expects($this->once())
92
            ->method('setCustomRepositoryClass')
93
            ->with($this->identicalTo($repository));
94
95
        $classMetadata->parentClasses = [];
0 ignored issues
show
Bug introduced by
Accessing parentClasses on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
96
        $classMetadata->isMappedSuperclass = false;
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
97
98
        $this->resourceSubscriber->loadClassMetadata($event);
99
100
        $this->assertFalse($classMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
101
    }
102
103 View Code Duplication
    public function testLoadClassMetadataWithResourceAndParentClassesWithoutInheritance()
0 ignored issues
show
Duplication introduced by
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
        $event = $this->createLoadClassMetadataEventArgsMock();
106
        $event
107
            ->expects($this->once())
108
            ->method('getClassMetadata')
109
            ->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
110
111
        $classMetadata
112
            ->expects($this->once())
113
            ->method('getName')
114
            ->will($this->returnValue($model = 'model'));
115
116
        $this->serviceRegistry
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Registry\Model\RegistryInterface.

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...
117
            ->expects($this->once())
118
            ->method('getIterator')
119
            ->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
120
121
        $resource
122
            ->expects($this->once())
123
            ->method('getModel')
124
            ->will($this->returnValue($model));
125
126
        $classMetadata->parentClasses = [$parentClass = 'ParentClass'];
0 ignored issues
show
Bug introduced by
Accessing parentClasses on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
127
128
        $event
129
            ->expects($this->once())
130
            ->method('getObjectManager')
131
            ->will($this->returnValue($objectManager = $this->createObjectManagerMock()));
132
133
        $objectManager
134
            ->expects($this->once())
135
            ->method('getClassMetadata')
136
            ->with($this->identicalTo($parentClass))
137
            ->will($this->returnValue($parentMetadata = $this->createClassMetadataMock()));
138
139
        $parentMetadata->isMappedSuperclass = false;
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
140
        $parentMetadata->inheritanceType = ClassMetadata::INHERITANCE_TYPE_NONE;
0 ignored issues
show
Bug introduced by
Accessing inheritanceType on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
141
142
        $resource
143
            ->expects($this->once())
144
            ->method('getRepository')
145
            ->will($this->returnValue($repository = 'repository'));
146
147
        $classMetadata
148
            ->expects($this->once())
149
            ->method('setCustomRepositoryClass')
150
            ->with($this->identicalTo($repository));
151
152
        $this->resourceSubscriber->loadClassMetadata($event);
153
154
        $this->assertFalse($classMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
155
        $this->assertTrue($parentMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
156
    }
157
158 View Code Duplication
    public function testLoadClassMetadataWithResourceAndParentClassesWithInheritance()
0 ignored issues
show
Duplication introduced by
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...
159
    {
160
        $event = $this->createLoadClassMetadataEventArgsMock();
161
        $event
162
            ->expects($this->once())
163
            ->method('getClassMetadata')
164
            ->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
165
166
        $classMetadata
167
            ->expects($this->once())
168
            ->method('getName')
169
            ->will($this->returnValue($model = 'model'));
170
171
        $this->serviceRegistry
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Registry\Model\RegistryInterface.

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...
172
            ->expects($this->once())
173
            ->method('getIterator')
174
            ->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
175
176
        $resource
177
            ->expects($this->once())
178
            ->method('getModel')
179
            ->will($this->returnValue($model));
180
181
        $classMetadata->parentClasses = [$parentClass = 'ParentClass'];
0 ignored issues
show
Bug introduced by
Accessing parentClasses on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
182
183
        $event
184
            ->expects($this->once())
185
            ->method('getObjectManager')
186
            ->will($this->returnValue($objectManager = $this->createObjectManagerMock()));
187
188
        $objectManager
189
            ->expects($this->once())
190
            ->method('getClassMetadata')
191
            ->with($this->identicalTo($parentClass))
192
            ->will($this->returnValue($parentMetadata = $this->createClassMetadataMock()));
193
194
        $parentMetadata->isMappedSuperclass = false;
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
195
        $parentMetadata->inheritanceType = ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION;
0 ignored issues
show
Bug introduced by
Accessing inheritanceType on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
196
197
        $resource
198
            ->expects($this->once())
199
            ->method('getRepository')
200
            ->will($this->returnValue($repository = 'repository'));
201
202
        $classMetadata
203
            ->expects($this->once())
204
            ->method('setCustomRepositoryClass')
205
            ->with($this->identicalTo($repository));
206
207
        $this->resourceSubscriber->loadClassMetadata($event);
208
209
        $this->assertFalse($classMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
210
        $this->assertFalse($parentMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
211
    }
212
213
    public function testLoadClassMetadataWithResourceAndParentClassesWithoutClassMetadata()
214
    {
215
        $event = $this->createLoadClassMetadataEventArgsMock();
216
        $event
217
            ->expects($this->once())
218
            ->method('getClassMetadata')
219
            ->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
220
221
        $classMetadata
222
            ->expects($this->once())
223
            ->method('getName')
224
            ->will($this->returnValue($model = 'model'));
225
226
        $this->serviceRegistry
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Registry\Model\RegistryInterface.

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...
227
            ->expects($this->once())
228
            ->method('getIterator')
229
            ->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));
230
231
        $resource
232
            ->expects($this->once())
233
            ->method('getModel')
234
            ->will($this->returnValue($model));
235
236
        $classMetadata->parentClasses = [$parentClass = 'ParentClass'];
0 ignored issues
show
Bug introduced by
Accessing parentClasses on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
237
238
        $event
239
            ->expects($this->once())
240
            ->method('getObjectManager')
241
            ->will($this->returnValue($objectManager = $this->createObjectManagerMock()));
242
243
        $objectManager
244
            ->expects($this->once())
245
            ->method('getClassMetadata')
246
            ->with($this->identicalTo($parentClass))
247
            ->will($this->throwException(new MappingException()));
248
249
        $resource
250
            ->expects($this->once())
251
            ->method('getRepository')
252
            ->will($this->returnValue($repository = 'repository'));
253
254
        $classMetadata
255
            ->expects($this->once())
256
            ->method('setCustomRepositoryClass')
257
            ->with($this->identicalTo($repository));
258
259
        $this->resourceSubscriber->loadClassMetadata($event);
260
261
        $this->assertFalse($classMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
262
    }
263
264 View Code Duplication
    public function testLoadClassMetadataWithoutResource()
0 ignored issues
show
Duplication introduced by
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...
265
    {
266
        $event = $this->createLoadClassMetadataEventArgsMock();
267
        $event
268
            ->expects($this->once())
269
            ->method('getClassMetadata')
270
            ->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
271
272
        $classMetadata
273
            ->expects($this->once())
274
            ->method('getName')
275
            ->will($this->returnValue($model = 'model'));
276
277
        $this->serviceRegistry
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Registry\Model\RegistryInterface.

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...
278
            ->expects($this->once())
279
            ->method('getIterator')
280
            ->will($this->returnValue(new \ArrayIterator([])));
281
282
        $classMetadata
283
            ->expects($this->never())
284
            ->method('setCustomRepositoryClass');
285
286
        $classMetadata->isMappedSuperclass = true;
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
287
288
        $this->resourceSubscriber->loadClassMetadata($event);
289
290
        $this->assertTrue($classMetadata->isMappedSuperclass);
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
291
    }
292
293
    /**
294
     * @return \PHPUnit_Framework_MockObject_MockObject|RegistryInterface
295
     */
296
    private function createServiceRegistryMock()
297
    {
298
        return $this->createMock(RegistryInterface::class);
299
    }
300
301
    /**
302
     * @return \PHPUnit_Framework_MockObject_MockObject|LoadClassMetadataEventArgs
303
     */
304
    private function createLoadClassMetadataEventArgsMock()
305
    {
306
        return $this->createMock(LoadClassMetadataEventArgs::class);
307
    }
308
309
    /**
310
     * @return \PHPUnit_Framework_MockObject_MockObject|ObjectManager
311
     */
312
    private function createObjectManagerMock()
313
    {
314
        return $this->createMock(ObjectManager::class);
315
    }
316
317
    /**
318
     * @return \PHPUnit_Framework_MockObject_MockObject|ClassMetadata
319
     */
320
    private function createClassMetadataMock()
321
    {
322
        return $this->createMock(ClassMetadata::class);
323
    }
324
325
    /**
326
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
327
     */
328
    private function createResourceMock()
329
    {
330
        return $this->createMock(ResourceInterface::class);
331
    }
332
}
333