Failed Conditions
Pull Request — master (#6900)
by
unknown
09:48
created

GH6884Person   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A onPostUpdate() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\ORM\Annotation as ORM;
8
use Doctrine\ORM\Event\LifecycleEventArgs;
9
use Doctrine\ORM\Events;
10
use Doctrine\Tests\OrmFunctionalTestCase;
11
use stdClass;
12
13
/**
14
 * @group 6884
15
 */
16
final class GH6884Test extends OrmFunctionalTestCase
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function setUp() : void
22
    {
23
        parent::setUp();
24
25
        $this->schemaTool->createSchema([$this->em->getClassMetadata(GH6884Person::class)]);
26
27
        $listener = $this->createPartialMock(stdClass::class, ['preUpdate']);
28
29
        $listener->expects($this->exactly(3))->method('preUpdate');
30
31
        $this->em->getEventManager()->addEventListener([Events::preUpdate], $listener);
32
33
        $this->em->getClassMetadata(GH6884Person::class)
34
                 ->addEntityListener(Events::postUpdate, GH6884Person::class, 'onPostUpdate');
0 ignored issues
show
Bug introduced by
The method addEntityListener() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                 ->/** @scrutinizer ignore-call */ addEntityListener(Events::postUpdate, GH6884Person::class, 'onPostUpdate');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
    }
36
37
    public function testIssue() : void
38
    {
39
        $person  = new GH6884Person();
40
        $person2 = new GH6884Person();
41
42
        $this->em->persist($person);
43
        $this->em->persist($person2);
44
        $this->em->flush();
45
46
        $person->isAlive  = true;
47
        $person2->isAlive = true;
48
49
        $this->em->flush();
50
    }
51
}
52
53
/**
54
 * @ORM\Entity()
55
 */
56
class GH6884Person
57
{
58
    /**
59
     * @ORM\Id()
60
     * @ORM\Column(type="integer")
61
     * @ORM\GeneratedValue()
62
     */
63
    public $id;
64
65
    /** @ORM\Column(type="boolean", nullable=false) */
66
    public $isAlive = false;
67
68
    /** @var bool */
69
    public $nonOrmProperty = false;
70
71
    public function onPostUpdate(GH6884Person $person, LifecycleEventArgs $eventArgs) : void
72
    {
73
        $person->nonOrmProperty = true;
74
75
        $eventArgs->getEntityManager()->flush();
76
    }
77
}
78