Completed
Push — master ( 8b59b0...fbc808 )
by Eric
30:26 queued 22:57
created

DomainManagerTest::testUpdateByPassException()   C

Complexity

Conditions 9
Paths 1

Size

Total Lines 71
Code Lines 52

Duplication

Lines 71
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 71
loc 71
rs 6.0993
cc 9
eloc 52
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Component\Resource\Tests\Domain;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Lug\Component\Resource\Domain\DomainEvent;
16
use Lug\Component\Resource\Domain\DomainManager;
17
use Lug\Component\Resource\Domain\DomainManagerInterface;
18
use Lug\Component\Resource\Exception\DomainException;
19
use Lug\Component\Resource\Model\ResourceInterface;
20
use Lug\Component\Resource\Repository\RepositoryInterface;
21
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
22
use Symfony\Component\HttpFoundation\Response;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class DomainManagerTest extends \PHPUnit_Framework_TestCase
28
{
29
    /**
30
     * @var DomainManager
31
     */
32
    private $domainManager;
33
34
    /**
35
     * @var \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
36
     */
37
    private $resource;
38
39
    /**
40
     * @var \PHPUnit_Framework_MockObject_MockObject|EventDispatcherInterface
41
     */
42
    private $eventDispatcher;
43
44
    /**
45
     * @var \PHPUnit_Framework_MockObject_MockObject|ObjectManager
46
     */
47
    private $objectManager;
48
49
    /**
50
     * @var \PHPUnit_Framework_MockObject_MockObject|RepositoryInterface
51
     */
52
    private $repository;
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function setUp()
58
    {
59
        $this->resource = $this->createResourceMock();
60
        $this->eventDispatcher = $this->createEventDispatcherMock();
61
        $this->objectManager = $this->createObjectManagerMock();
62
        $this->repository = $this->createRepositoryMock();
63
64
        $this->domainManager = new DomainManager(
65
            $this->resource,
66
            $this->eventDispatcher,
67
            $this->objectManager,
68
            $this->repository
69
        );
70
    }
71
72
    public function testInheritance()
73
    {
74
        $this->assertInstanceOf(DomainManagerInterface::class, $this->domainManager);
75
    }
76
77
    public function testFind()
78
    {
79
        $this->resource
80
            ->expects($this->exactly(2))
81
            ->method('getName')
82
            ->will($this->returnValue($name = 'name'));
83
84
        $this->repository
85
            ->expects($this->once())
86
            ->method($repositoryMethod = 'findForShow')
87
            ->with(
88
                $this->identicalTo($criteria = ['criteria']),
89
                $this->identicalTo($sorting = ['sorting'])
90
            )
91
            ->will($this->returnValue($object = new \stdClass()));
92
93
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
94
            ->expects($this->at(0))
95
            ->method('dispatch')
96
            ->with(
97
                $this->identicalTo('lug.'.$name.'.pre_find.'.($action = 'action')),
98
                $this->callback(function (DomainEvent $event) use ($action) {
99
                    return $event->getResource() === $this->resource
100
                        && $event->getObject() === null
101
                        && $event->getAction() === 'find.'.$action;
102
                })
103
            );
104
105
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
106
            ->expects($this->at(1))
107
            ->method('dispatch')
108
            ->with(
109
                $this->identicalTo('lug.'.$name.'.post_find.'.$action),
110
                $this->callback(function (DomainEvent $event) use ($object, $action) {
111
                    return $event->getResource() === $this->resource
112
                    && $event->getObject() === $object
113
                    && $event->getAction() === 'find.'.$action;
114
                })
115
            );
116
117
        $this->assertSame($object, $this->domainManager->find($action, $repositoryMethod, $criteria, $sorting));
118
    }
119
120
    public function testFindThrowException()
121
    {
122
        $this->resource
123
            ->expects($this->exactly(2))
124
            ->method('getName')
125
            ->will($this->returnValue($name = 'name'));
126
127
        $this->repository
128
            ->expects($this->once())
129
            ->method($repositoryMethod = 'findForShow')
130
            ->with(
131
                $this->identicalTo($criteria = ['criteria']),
132
                $this->identicalTo($sorting = ['sorting'])
133
            )
134
            ->will($this->throwException(new \Exception()));
135
136
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
137
            ->expects($this->at(0))
138
            ->method('dispatch')
139
            ->with(
140
                $this->identicalTo('lug.'.$name.'.pre_find.'.($action = 'action')),
141
                $this->callback(function (DomainEvent $event) use ($action) {
142
                    return $event->getResource() === $this->resource
143
                        && $event->getObject() === null
144
                        && $event->getAction() === 'find.'.$action;
145
                })
146
            );
147
148
        $statusCode = Response::HTTP_BAD_REQUEST;
149
        $message = 'message';
150
151
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
152
            ->expects($this->at(1))
153
            ->method('dispatch')
154
            ->with(
155
                $this->identicalTo('lug.'.$name.'.error_find.'.$action),
156
                $this->callback(function (DomainEvent $event) use ($action, $statusCode, $message) {
157
                    $result = $event->getResource() === $this->resource
158
                        && $event->getObject() === null
159
                        && $event->getAction() === 'find.'.$action;
160
161
                    $event->setStatusCode($statusCode);
162
                    $event->setMessage($message);
163
164
                    return $result;
165
                })
166
            );
167
168
        try {
169
            $this->domainManager->find($action, $repositoryMethod, $criteria, $sorting);
170
            $this->fail();
171
        } catch (DomainException $e) {
172
            $this->assertSame($statusCode, $e->getStatusCode());
173
            $this->assertSame($message, $e->getMessage());
174
        }
175
    }
176
177
    public function testFindByPassException()
178
    {
179
        $this->resource
180
            ->expects($this->exactly(2))
181
            ->method('getName')
182
            ->will($this->returnValue($name = 'name'));
183
184
        $this->repository
185
            ->expects($this->once())
186
            ->method($repositoryMethod = 'findForShow')
187
            ->with(
188
                $this->identicalTo($criteria = ['criteria']),
189
                $this->identicalTo($sorting = ['sorting'])
190
            )
191
            ->will($this->throwException(new \Exception()));
192
193
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
194
            ->expects($this->at(0))
195
            ->method('dispatch')
196
            ->with(
197
                $this->identicalTo('lug.'.$name.'.pre_find.'.($action = 'action')),
198
                $this->callback(function (DomainEvent $event) use ($action) {
199
                    return $event->getResource() === $this->resource
200
                    && $event->getObject() === null
201
                    && $event->getAction() === 'find.'.$action;
202
                })
203
            );
204
205
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
206
            ->expects($this->at(1))
207
            ->method('dispatch')
208
            ->with(
209
                $this->identicalTo('lug.'.$name.'.error_find.'.$action),
210
                $this->callback(function (DomainEvent $event) use ($action) {
211
                    $result = $event->getResource() === $this->resource
212
                        && $event->getObject() === null
213
                        && $event->getAction() === 'find.'.$action;
214
215
                    $event->setStopped(false);
216
217
                    return $result;
218
                })
219
            );
220
221
        $this->assertNull($this->domainManager->find($action, $repositoryMethod, $criteria, $sorting));
222
    }
223
224 View Code Duplication
    public function testCreate()
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...
225
    {
226
        $this->resource
227
            ->expects($this->exactly(4))
228
            ->method('getName')
229
            ->will($this->returnValue($name = 'name'));
230
231
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
232
            ->expects($this->once())
233
            ->method('persist')
234
            ->with($this->identicalTo($object = new \stdClass()));
235
236
        $this->objectManager
237
            ->expects($this->once())
238
            ->method('flush');
239
240
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
241
            ->expects($this->at(0))
242
            ->method('dispatch')
243
            ->with(
244
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
245
                $this->callback(function (DomainEvent $event) use ($createAction, $object) {
246
                    return $event->getResource() === $this->resource
247
                        && $event->getObject() === $object
248
                        && $event->getAction() === $createAction;
249
                })
250
            );
251
252
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
253
            ->expects($this->at(1))
254
            ->method('dispatch')
255
            ->with(
256
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
257
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
258
                    return $event->getResource() === $this->resource
259
                        && $event->getObject() === $object
260
                        && $event->getAction() === $flushAction;
261
                })
262
            );
263
264
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
265
            ->expects($this->at(2))
266
            ->method('dispatch')
267
            ->with(
268
                $this->identicalTo('lug.'.$name.'.post_'.$flushAction),
269
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
270
                    return $event->getResource() === $this->resource
271
                        && $event->getObject() === $object
272
                        && $event->getAction() === $flushAction;
273
                })
274
            );
275
276
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
277
            ->expects($this->at(3))
278
            ->method('dispatch')
279
            ->with(
280
                $this->identicalTo('lug.'.$name.'.post_'.$createAction),
281
                $this->callback(function (DomainEvent $event) use ($object, $createAction) {
282
                    return $event->getResource() === $this->resource
283
                        && $event->getObject() === $object
284
                        && $event->getAction() === $createAction;
285
                })
286
            );
287
288
        $this->domainManager->create($object);
289
    }
290
291 View Code Duplication
    public function testCreateWithoutFlush()
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...
292
    {
293
        $this->resource
294
            ->expects($this->exactly(2))
295
            ->method('getName')
296
            ->will($this->returnValue($name = 'name'));
297
298
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
299
            ->expects($this->once())
300
            ->method('persist')
301
            ->with($this->identicalTo($object = new \stdClass()));
302
303
        $this->objectManager
304
            ->expects($this->never())
305
            ->method('flush');
306
307
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
308
            ->expects($this->at(0))
309
            ->method('dispatch')
310
            ->with(
311
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
312
                $this->callback(function (DomainEvent $event) use ($createAction, $object) {
313
                    return $event->getResource() === $this->resource
314
                    && $event->getObject() === $object
315
                    && $event->getAction() === $createAction;
316
                })
317
            );
318
319
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
320
            ->expects($this->at(1))
321
            ->method('dispatch')
322
            ->with(
323
                $this->identicalTo('lug.'.$name.'.post_'.$createAction),
324
                $this->callback(function (DomainEvent $event) use ($object, $createAction) {
325
                    return $event->getResource() === $this->resource
326
                    && $event->getObject() === $object
327
                    && $event->getAction() === $createAction;
328
                })
329
            );
330
331
        $this->domainManager->create($object, false);
332
    }
333
334 View Code Duplication
    public function testCreateThrowException()
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...
335
    {
336
        $this->resource
337
            ->expects($this->exactly(4))
338
            ->method('getName')
339
            ->will($this->returnValue($name = 'name'));
340
341
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
342
            ->expects($this->once())
343
            ->method('persist')
344
            ->with($this->identicalTo($object = new \stdClass()));
345
346
        $this->objectManager
347
            ->expects($this->once())
348
            ->method('flush')
349
            ->will($this->throwException(new \Exception()));
350
351
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
352
            ->expects($this->at(0))
353
            ->method('dispatch')
354
            ->with(
355
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
356
                $this->callback(function (DomainEvent $event) use ($createAction, $object) {
357
                    return $event->getResource() === $this->resource
358
                        && $event->getObject() === $object
359
                        && $event->getAction() === $createAction;
360
                })
361
            );
362
363
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
364
            ->expects($this->at(1))
365
            ->method('dispatch')
366
            ->with(
367
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
368
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
369
                    return $event->getResource() === $this->resource
370
                        && $event->getObject() === $object
371
                        && $event->getAction() === $flushAction;
372
                })
373
            );
374
375
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
376
            ->expects($this->at(2))
377
            ->method('dispatch')
378
            ->with(
379
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
380
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
381
                    return $event->getResource() === $this->resource
382
                        && $event->getObject() === $object
383
                        && $event->getAction() === $flushAction;
384
                })
385
            );
386
387
        $statusCode = Response::HTTP_BAD_REQUEST;
388
        $message = 'message';
389
390
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
391
            ->expects($this->at(3))
392
            ->method('dispatch')
393
            ->with(
394
                $this->identicalTo('lug.'.$name.'.error_'.$createAction),
395
                $this->callback(function (DomainEvent $event) use ($object, $createAction, $statusCode, $message) {
396
                    $result = $event->getResource() === $this->resource
397
                        && $event->getObject() === $object
398
                        && $event->getAction() === $createAction;
399
400
                    $event->setStatusCode($statusCode);
401
                    $event->setMessage($message);
402
403
                    return $result;
404
                })
405
            );
406
407
        try {
408
            $this->domainManager->create($object);
409
            $this->fail();
410
        } catch (DomainException $e) {
411
            $this->assertSame($statusCode, $e->getStatusCode());
412
            $this->assertSame($message, $e->getMessage());
413
        }
414
    }
415
416 View Code Duplication
    public function testCreateByPassException()
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...
417
    {
418
        $this->resource
419
            ->expects($this->exactly(4))
420
            ->method('getName')
421
            ->will($this->returnValue($name = 'name'));
422
423
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
424
            ->expects($this->once())
425
            ->method('persist')
426
            ->with($this->identicalTo($object = new \stdClass()));
427
428
        $this->objectManager
429
            ->expects($this->once())
430
            ->method('flush')
431
            ->will($this->throwException(new \Exception()));
432
433
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
434
            ->expects($this->at(0))
435
            ->method('dispatch')
436
            ->with(
437
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
438
                $this->callback(function (DomainEvent $event) use ($createAction, $object) {
439
                    return $event->getResource() === $this->resource
440
                    && $event->getObject() === $object
441
                    && $event->getAction() === $createAction;
442
                })
443
            );
444
445
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
446
            ->expects($this->at(1))
447
            ->method('dispatch')
448
            ->with(
449
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
450
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
451
                    return $event->getResource() === $this->resource
452
                    && $event->getObject() === $object
453
                    && $event->getAction() === $flushAction;
454
                })
455
            );
456
457
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
458
            ->expects($this->at(2))
459
            ->method('dispatch')
460
            ->with(
461
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
462
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
463
                    return $event->getResource() === $this->resource
464
                    && $event->getObject() === $object
465
                    && $event->getAction() === $flushAction;
466
                })
467
            );
468
469
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
470
            ->expects($this->at(3))
471
            ->method('dispatch')
472
            ->with(
473
                $this->identicalTo('lug.'.$name.'.error_'.$createAction),
474
                $this->callback(function (DomainEvent $event) use ($object, $createAction) {
475
                    $result = $event->getResource() === $this->resource
476
                        && $event->getObject() === $object
477
                        && $event->getAction() === $createAction;
478
479
                    $event->setStopped(false);
480
481
                    return $result;
482
                })
483
            );
484
485
        $this->domainManager->create($object);
486
    }
487
488 View Code Duplication
    public function testUpdateWithManagedObject()
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...
489
    {
490
        $this->resource
491
            ->expects($this->exactly(4))
492
            ->method('getName')
493
            ->will($this->returnValue($name = 'name'));
494
495
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
496
            ->expects($this->once())
497
            ->method('contains')
498
            ->with($this->identicalTo($object = new \stdClass()))
499
            ->will($this->returnValue(true));
500
501
        $this->objectManager
502
            ->expects($this->never())
503
            ->method('persist');
504
505
        $this->objectManager
506
            ->expects($this->once())
507
            ->method('flush');
508
509
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
510
            ->expects($this->at(0))
511
            ->method('dispatch')
512
            ->with(
513
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
514
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
515
                    return $event->getResource() === $this->resource
516
                    && $event->getObject() === $object
517
                    && $event->getAction() === $updateAction;
518
                })
519
            );
520
521
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
522
            ->expects($this->at(1))
523
            ->method('dispatch')
524
            ->with(
525
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
526
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
527
                    return $event->getResource() === $this->resource
528
                    && $event->getObject() === $object
529
                    && $event->getAction() === $flushAction;
530
                })
531
            );
532
533
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
534
            ->expects($this->at(2))
535
            ->method('dispatch')
536
            ->with(
537
                $this->identicalTo('lug.'.$name.'.post_'.$flushAction),
538
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
539
                    return $event->getResource() === $this->resource
540
                    && $event->getObject() === $object
541
                    && $event->getAction() === $flushAction;
542
                })
543
            );
544
545
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
546
            ->expects($this->at(3))
547
            ->method('dispatch')
548
            ->with(
549
                $this->identicalTo('lug.'.$name.'.post_'.$updateAction),
550
                $this->callback(function (DomainEvent $event) use ($object, $updateAction) {
551
                    return $event->getResource() === $this->resource
552
                    && $event->getObject() === $object
553
                    && $event->getAction() === $updateAction;
554
                })
555
            );
556
557
        $this->domainManager->update($object);
558
    }
559
560 View Code Duplication
    public function testUpdateWithoutManagedObject()
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...
561
    {
562
        $this->resource
563
            ->expects($this->exactly(4))
564
            ->method('getName')
565
            ->will($this->returnValue($name = 'name'));
566
567
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
568
            ->expects($this->once())
569
            ->method('contains')
570
            ->with($this->identicalTo($object = new \stdClass()))
571
            ->will($this->returnValue(false));
572
573
        $this->objectManager
574
            ->expects($this->once())
575
            ->method('persist')
576
            ->with($this->identicalTo($object));
577
578
        $this->objectManager
579
            ->expects($this->once())
580
            ->method('flush');
581
582
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
583
            ->expects($this->at(0))
584
            ->method('dispatch')
585
            ->with(
586
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
587
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
588
                    return $event->getResource() === $this->resource
589
                    && $event->getObject() === $object
590
                    && $event->getAction() === $updateAction;
591
                })
592
            );
593
594
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
595
            ->expects($this->at(1))
596
            ->method('dispatch')
597
            ->with(
598
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
599
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
600
                    return $event->getResource() === $this->resource
601
                    && $event->getObject() === $object
602
                    && $event->getAction() === $flushAction;
603
                })
604
            );
605
606
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
607
            ->expects($this->at(2))
608
            ->method('dispatch')
609
            ->with(
610
                $this->identicalTo('lug.'.$name.'.post_'.$flushAction),
611
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
612
                    return $event->getResource() === $this->resource
613
                    && $event->getObject() === $object
614
                    && $event->getAction() === $flushAction;
615
                })
616
            );
617
618
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
619
            ->expects($this->at(3))
620
            ->method('dispatch')
621
            ->with(
622
                $this->identicalTo('lug.'.$name.'.post_'.$updateAction),
623
                $this->callback(function (DomainEvent $event) use ($object, $updateAction) {
624
                    return $event->getResource() === $this->resource
625
                    && $event->getObject() === $object
626
                    && $event->getAction() === $updateAction;
627
                })
628
            );
629
630
        $this->domainManager->update($object);
631
    }
632
633 View Code Duplication
    public function testUpdateWithoutFlush()
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...
634
    {
635
        $this->resource
636
            ->expects($this->exactly(2))
637
            ->method('getName')
638
            ->will($this->returnValue($name = 'name'));
639
640
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
641
            ->expects($this->once())
642
            ->method('persist')
643
            ->with($this->identicalTo($object = new \stdClass()));
644
645
        $this->objectManager
646
            ->expects($this->never())
647
            ->method('flush');
648
649
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
650
            ->expects($this->at(0))
651
            ->method('dispatch')
652
            ->with(
653
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
654
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
655
                    return $event->getResource() === $this->resource
656
                    && $event->getObject() === $object
657
                    && $event->getAction() === $updateAction;
658
                })
659
            );
660
661
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
662
            ->expects($this->at(1))
663
            ->method('dispatch')
664
            ->with(
665
                $this->identicalTo('lug.'.$name.'.post_'.$updateAction),
666
                $this->callback(function (DomainEvent $event) use ($object, $updateAction) {
667
                    return $event->getResource() === $this->resource
668
                    && $event->getObject() === $object
669
                    && $event->getAction() === $updateAction;
670
                })
671
            );
672
673
        $this->domainManager->update($object, false);
674
    }
675
676 View Code Duplication
    public function testUpdateThrowException()
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...
677
    {
678
        $this->resource
679
            ->expects($this->exactly(4))
680
            ->method('getName')
681
            ->will($this->returnValue($name = 'name'));
682
683
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
684
            ->expects($this->once())
685
            ->method('persist')
686
            ->with($this->identicalTo($object = new \stdClass()));
687
688
        $this->objectManager
689
            ->expects($this->once())
690
            ->method('flush')
691
            ->will($this->throwException(new \Exception()));
692
693
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
694
            ->expects($this->at(0))
695
            ->method('dispatch')
696
            ->with(
697
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
698
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
699
                    return $event->getResource() === $this->resource
700
                    && $event->getObject() === $object
701
                    && $event->getAction() === $updateAction;
702
                })
703
            );
704
705
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
706
            ->expects($this->at(1))
707
            ->method('dispatch')
708
            ->with(
709
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
710
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
711
                    return $event->getResource() === $this->resource
712
                    && $event->getObject() === $object
713
                    && $event->getAction() === $flushAction;
714
                })
715
            );
716
717
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
718
            ->expects($this->at(2))
719
            ->method('dispatch')
720
            ->with(
721
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
722
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
723
                    return $event->getResource() === $this->resource
724
                    && $event->getObject() === $object
725
                    && $event->getAction() === $flushAction;
726
                })
727
            );
728
729
        $statusCode = Response::HTTP_BAD_REQUEST;
730
        $message = 'message';
731
732
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
733
            ->expects($this->at(3))
734
            ->method('dispatch')
735
            ->with(
736
                $this->identicalTo('lug.'.$name.'.error_'.$updateAction),
737
                $this->callback(function (DomainEvent $event) use ($object, $updateAction, $statusCode, $message) {
738
                    $result = $event->getResource() === $this->resource
739
                        && $event->getObject() === $object
740
                        && $event->getAction() === $updateAction;
741
742
                    $event->setStatusCode($statusCode);
743
                    $event->setMessage($message);
744
745
                    return $result;
746
                })
747
            );
748
749
        try {
750
            $this->domainManager->update($object);
751
            $this->fail();
752
        } catch (DomainException $e) {
753
            $this->assertSame($statusCode, $e->getStatusCode());
754
            $this->assertSame($message, $e->getMessage());
755
        }
756
    }
757
758 View Code Duplication
    public function testUpdateByPassException()
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...
759
    {
760
        $this->resource
761
            ->expects($this->exactly(4))
762
            ->method('getName')
763
            ->will($this->returnValue($name = 'name'));
764
765
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
766
            ->expects($this->once())
767
            ->method('persist')
768
            ->with($this->identicalTo($object = new \stdClass()));
769
770
        $this->objectManager
771
            ->expects($this->once())
772
            ->method('flush')
773
            ->will($this->throwException(new \Exception()));
774
775
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
776
            ->expects($this->at(0))
777
            ->method('dispatch')
778
            ->with(
779
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
780
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
781
                    return $event->getResource() === $this->resource
782
                    && $event->getObject() === $object
783
                    && $event->getAction() === $updateAction;
784
                })
785
            );
786
787
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
788
            ->expects($this->at(1))
789
            ->method('dispatch')
790
            ->with(
791
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
792
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
793
                    return $event->getResource() === $this->resource
794
                    && $event->getObject() === $object
795
                    && $event->getAction() === $flushAction;
796
                })
797
            );
798
799
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
800
            ->expects($this->at(2))
801
            ->method('dispatch')
802
            ->with(
803
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
804
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
805
                    return $event->getResource() === $this->resource
806
                    && $event->getObject() === $object
807
                    && $event->getAction() === $flushAction;
808
                })
809
            );
810
811
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
812
            ->expects($this->at(3))
813
            ->method('dispatch')
814
            ->with(
815
                $this->identicalTo('lug.'.$name.'.error_'.$updateAction),
816
                $this->callback(function (DomainEvent $event) use ($object, $updateAction) {
817
                    $result = $event->getResource() === $this->resource
818
                        && $event->getObject() === $object
819
                        && $event->getAction() === $updateAction;
820
821
                    $event->setStopped(false);
822
823
                    return $result;
824
                })
825
            );
826
827
        $this->domainManager->update($object);
828
    }
829
830 View Code Duplication
    public function testDelete()
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...
831
    {
832
        $this->resource
833
            ->expects($this->exactly(4))
834
            ->method('getName')
835
            ->will($this->returnValue($name = 'name'));
836
837
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
838
            ->expects($this->once())
839
            ->method('remove')
840
            ->with($this->identicalTo($object = new \stdClass()));
841
842
        $this->objectManager
843
            ->expects($this->once())
844
            ->method('flush');
845
846
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
847
            ->expects($this->at(0))
848
            ->method('dispatch')
849
            ->with(
850
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
851
                $this->callback(function (DomainEvent $event) use ($deleteAction, $object) {
852
                    return $event->getResource() === $this->resource
853
                    && $event->getObject() === $object
854
                    && $event->getAction() === $deleteAction;
855
                })
856
            );
857
858
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
859
            ->expects($this->at(1))
860
            ->method('dispatch')
861
            ->with(
862
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
863
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
864
                    return $event->getResource() === $this->resource
865
                    && $event->getObject() === $object
866
                    && $event->getAction() === $flushAction;
867
                })
868
            );
869
870
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
871
            ->expects($this->at(2))
872
            ->method('dispatch')
873
            ->with(
874
                $this->identicalTo('lug.'.$name.'.post_'.$flushAction),
875
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
876
                    return $event->getResource() === $this->resource
877
                    && $event->getObject() === $object
878
                    && $event->getAction() === $flushAction;
879
                })
880
            );
881
882
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
883
            ->expects($this->at(3))
884
            ->method('dispatch')
885
            ->with(
886
                $this->identicalTo('lug.'.$name.'.post_'.$deleteAction),
887
                $this->callback(function (DomainEvent $event) use ($object, $deleteAction) {
888
                    return $event->getResource() === $this->resource
889
                    && $event->getObject() === $object
890
                    && $event->getAction() === $deleteAction;
891
                })
892
            );
893
894
        $this->domainManager->delete($object);
895
    }
896
897 View Code Duplication
    public function testDeleteWithoutFlush()
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...
898
    {
899
        $this->resource
900
            ->expects($this->exactly(2))
901
            ->method('getName')
902
            ->will($this->returnValue($name = 'name'));
903
904
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
905
            ->expects($this->once())
906
            ->method('remove')
907
            ->with($this->identicalTo($object = new \stdClass()));
908
909
        $this->objectManager
910
            ->expects($this->never())
911
            ->method('flush');
912
913
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
914
            ->expects($this->at(0))
915
            ->method('dispatch')
916
            ->with(
917
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
918
                $this->callback(function (DomainEvent $event) use ($deleteAction, $object) {
919
                    return $event->getResource() === $this->resource
920
                    && $event->getObject() === $object
921
                    && $event->getAction() === $deleteAction;
922
                })
923
            );
924
925
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
926
            ->expects($this->at(1))
927
            ->method('dispatch')
928
            ->with(
929
                $this->identicalTo('lug.'.$name.'.post_'.$deleteAction),
930
                $this->callback(function (DomainEvent $event) use ($object, $deleteAction) {
931
                    return $event->getResource() === $this->resource
932
                    && $event->getObject() === $object
933
                    && $event->getAction() === $deleteAction;
934
                })
935
            );
936
937
        $this->domainManager->delete($object, false);
938
    }
939
940 View Code Duplication
    public function testDeleteThrowException()
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...
941
    {
942
        $this->resource
943
            ->expects($this->exactly(4))
944
            ->method('getName')
945
            ->will($this->returnValue($name = 'name'));
946
947
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
948
            ->expects($this->once())
949
            ->method('remove')
950
            ->with($this->identicalTo($object = new \stdClass()));
951
952
        $this->objectManager
953
            ->expects($this->once())
954
            ->method('flush')
955
            ->will($this->throwException(new \Exception()));
956
957
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
958
            ->expects($this->at(0))
959
            ->method('dispatch')
960
            ->with(
961
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
962
                $this->callback(function (DomainEvent $event) use ($deleteAction, $object) {
963
                    return $event->getResource() === $this->resource
964
                    && $event->getObject() === $object
965
                    && $event->getAction() === $deleteAction;
966
                })
967
            );
968
969
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
970
            ->expects($this->at(1))
971
            ->method('dispatch')
972
            ->with(
973
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
974
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
975
                    return $event->getResource() === $this->resource
976
                    && $event->getObject() === $object
977
                    && $event->getAction() === $flushAction;
978
                })
979
            );
980
981
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
982
            ->expects($this->at(2))
983
            ->method('dispatch')
984
            ->with(
985
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
986
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
987
                    return $event->getResource() === $this->resource
988
                    && $event->getObject() === $object
989
                    && $event->getAction() === $flushAction;
990
                })
991
            );
992
993
        $statusCode = Response::HTTP_BAD_REQUEST;
994
        $message = 'message';
995
996
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
997
            ->expects($this->at(3))
998
            ->method('dispatch')
999
            ->with(
1000
                $this->identicalTo('lug.'.$name.'.error_'.$deleteAction),
1001
                $this->callback(function (DomainEvent $event) use ($object, $deleteAction, $statusCode, $message) {
1002
                    $result = $event->getResource() === $this->resource
1003
                        && $event->getObject() === $object
1004
                        && $event->getAction() === $deleteAction;
1005
1006
                    $event->setStatusCode($statusCode);
1007
                    $event->setMessage($message);
1008
1009
                    return $result;
1010
                })
1011
            );
1012
1013
        try {
1014
            $this->domainManager->delete($object);
1015
            $this->fail();
1016
        } catch (DomainException $e) {
1017
            $this->assertSame($statusCode, $e->getStatusCode());
1018
            $this->assertSame($message, $e->getMessage());
1019
        }
1020
    }
1021
1022 View Code Duplication
    public function testDeleteByPassException()
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...
1023
    {
1024
        $this->resource
1025
            ->expects($this->exactly(4))
1026
            ->method('getName')
1027
            ->will($this->returnValue($name = 'name'));
1028
1029
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
1030
            ->expects($this->once())
1031
            ->method('remove')
1032
            ->with($this->identicalTo($object = new \stdClass()));
1033
1034
        $this->objectManager
1035
            ->expects($this->once())
1036
            ->method('flush')
1037
            ->will($this->throwException(new \Exception()));
1038
1039
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1040
            ->expects($this->at(0))
1041
            ->method('dispatch')
1042
            ->with(
1043
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
1044
                $this->callback(function (DomainEvent $event) use ($deleteAction, $object) {
1045
                    return $event->getResource() === $this->resource
1046
                    && $event->getObject() === $object
1047
                    && $event->getAction() === $deleteAction;
1048
                })
1049
            );
1050
1051
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1052
            ->expects($this->at(1))
1053
            ->method('dispatch')
1054
            ->with(
1055
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
1056
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
1057
                    return $event->getResource() === $this->resource
1058
                    && $event->getObject() === $object
1059
                    && $event->getAction() === $flushAction;
1060
                })
1061
            );
1062
1063
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1064
            ->expects($this->at(2))
1065
            ->method('dispatch')
1066
            ->with(
1067
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
1068
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
1069
                    return $event->getResource() === $this->resource
1070
                    && $event->getObject() === $object
1071
                    && $event->getAction() === $flushAction;
1072
                })
1073
            );
1074
1075
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1076
            ->expects($this->at(3))
1077
            ->method('dispatch')
1078
            ->with(
1079
                $this->identicalTo('lug.'.$name.'.error_'.$deleteAction),
1080
                $this->callback(function (DomainEvent $event) use ($object, $deleteAction) {
1081
                    $result = $event->getResource() === $this->resource
1082
                        && $event->getObject() === $object
1083
                        && $event->getAction() === $deleteAction;
1084
1085
                    $event->setStopped(false);
1086
1087
                    return $result;
1088
                })
1089
            );
1090
1091
        $this->domainManager->delete($object);
1092
    }
1093
1094
    public function testFlush()
1095
    {
1096
        $this->resource
1097
            ->expects($this->exactly(2))
1098
            ->method('getName')
1099
            ->will($this->returnValue($name = 'name'));
1100
1101
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
1102
            ->expects($this->once())
1103
            ->method('flush');
1104
1105
        $object = new \stdClass();
1106
1107
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1108
            ->expects($this->at(0))
1109
            ->method('dispatch')
1110
            ->with(
1111
                $this->identicalTo('lug.'.$name.'.pre_'.($action = 'flush')),
1112
                $this->callback(function (DomainEvent $event) use ($action, $object) {
1113
                    return $event->getResource() === $this->resource
1114
                    && $event->getObject() === $object
1115
                    && $event->getAction() === $action;
1116
                })
1117
            );
1118
1119
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1120
            ->expects($this->at(1))
1121
            ->method('dispatch')
1122
            ->with(
1123
                $this->identicalTo('lug.'.$name.'.post_'.$action),
1124
                $this->callback(function (DomainEvent $event) use ($action, $object) {
1125
                    return $event->getResource() === $this->resource
1126
                    && $event->getObject() === $object
1127
                    && $event->getAction() === $action;
1128
                })
1129
            );
1130
1131
        $this->domainManager->flush($object);
1132
    }
1133
1134
    public function testFlushWithoutObject()
1135
    {
1136
        $this->resource
1137
            ->expects($this->exactly(2))
1138
            ->method('getName')
1139
            ->will($this->returnValue($name = 'name'));
1140
1141
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
1142
            ->expects($this->once())
1143
            ->method('flush');
1144
1145
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1146
            ->expects($this->at(0))
1147
            ->method('dispatch')
1148
            ->with(
1149
                $this->identicalTo('lug.'.$name.'.pre_'.($action = 'flush')),
1150
                $this->callback(function (DomainEvent $event) use ($action) {
1151
                    return $event->getResource() === $this->resource
1152
                    && $event->getObject() === null
1153
                    && $event->getAction() === $action;
1154
                })
1155
            );
1156
1157
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1158
            ->expects($this->at(1))
1159
            ->method('dispatch')
1160
            ->with(
1161
                $this->identicalTo('lug.'.$name.'.post_'.$action),
1162
                $this->callback(function (DomainEvent $event) use ($action) {
1163
                    return $event->getResource() === $this->resource
1164
                    && $event->getObject() === null
1165
                    && $event->getAction() === $action;
1166
                })
1167
            );
1168
1169
        $this->domainManager->flush();
1170
    }
1171
1172
    public function testFlushThrowException()
1173
    {
1174
        $this->resource
1175
            ->expects($this->exactly(2))
1176
            ->method('getName')
1177
            ->will($this->returnValue($name = 'name'));
1178
1179
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
1180
            ->expects($this->once())
1181
            ->method('flush')
1182
            ->will($this->throwException(new \Exception()));
1183
1184
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1185
            ->expects($this->at(0))
1186
            ->method('dispatch')
1187
            ->with(
1188
                $this->identicalTo('lug.'.$name.'.pre_'.($action = 'flush')),
1189
                $this->callback(function (DomainEvent $event) use ($action) {
1190
                    return $event->getResource() === $this->resource
1191
                    && $event->getObject() === null
1192
                    && $event->getAction() === $action;
1193
                })
1194
            );
1195
1196
        $statusCode = Response::HTTP_BAD_REQUEST;
1197
        $message = 'message';
1198
1199
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1200
            ->expects($this->at(1))
1201
            ->method('dispatch')
1202
            ->with(
1203
                $this->identicalTo('lug.'.$name.'.error_'.$action),
1204
                $this->callback(function (DomainEvent $event) use ($action, $statusCode, $message) {
1205
                    $result = $event->getResource() === $this->resource
1206
                        && $event->getObject() === null
1207
                        && $event->getAction() === $action;
1208
1209
                    $event->setStatusCode($statusCode);
1210
                    $event->setMessage($message);
1211
1212
                    return $result;
1213
                })
1214
            );
1215
1216
        try {
1217
            $this->domainManager->flush();
1218
            $this->fail();
1219
        } catch (DomainException $e) {
1220
            $this->assertSame($statusCode, $e->getStatusCode());
1221
            $this->assertSame($message, $e->getMessage());
1222
        }
1223
    }
1224
1225
    public function testFlushByPassException()
1226
    {
1227
        $this->resource
1228
            ->expects($this->exactly(2))
1229
            ->method('getName')
1230
            ->will($this->returnValue($name = 'name'));
1231
1232
        $this->objectManager
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

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...
1233
            ->expects($this->once())
1234
            ->method('flush')
1235
            ->will($this->throwException(new \Exception()));
1236
1237
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1238
            ->expects($this->at(0))
1239
            ->method('dispatch')
1240
            ->with(
1241
                $this->identicalTo('lug.'.$name.'.pre_'.($action = 'flush')),
1242
                $this->callback(function (DomainEvent $event) use ($action) {
1243
                    return $event->getResource() === $this->resource
1244
                        && $event->getObject() === null
1245
                        && $event->getAction() === $action;
1246
                })
1247
            );
1248
1249
        $this->eventDispatcher
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\EventD...ventDispatcherInterface.

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...
1250
            ->expects($this->at(1))
1251
            ->method('dispatch')
1252
            ->with(
1253
                $this->identicalTo('lug.'.$name.'.error_'.$action),
1254
                $this->callback(function (DomainEvent $event) use ($action) {
1255
                    $result = $event->getResource() === $this->resource
1256
                        && $event->getObject() === null
1257
                        && $event->getAction() === $action;
1258
1259
                    $event->setStopped(false);
1260
1261
                    return $result;
1262
                })
1263
            );
1264
1265
        $this->domainManager->flush();
1266
    }
1267
1268
    /**
1269
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
1270
     */
1271
    private function createResourceMock()
1272
    {
1273
        return $this->createMock(ResourceInterface::class);
1274
    }
1275
1276
    /**
1277
     * @return \PHPUnit_Framework_MockObject_MockObject|EventDispatcherInterface
1278
     */
1279
    private function createEventDispatcherMock()
1280
    {
1281
        return $this->createMock(EventDispatcherInterface::class);
1282
    }
1283
1284
    /**
1285
     * @return \PHPUnit_Framework_MockObject_MockObject|ObjectManager
1286
     */
1287
    private function createObjectManagerMock()
1288
    {
1289
        return $this->createMock(ObjectManager::class);
1290
    }
1291
1292
    /**
1293
     * @return \PHPUnit_Framework_MockObject_MockObject|RepositoryInterface
1294
     */
1295
    private function createRepositoryMock()
1296
    {
1297
        return $this->createMock(RepositoryInterface::class);
1298
    }
1299
}
1300