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

GH6884Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 18 1
A testIssue() 0 13 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\ORM\Event\LifecycleEventArgs;
6
use Doctrine\ORM\Events;
7
use Doctrine\Tests\OrmFunctionalTestCase;
8
use stdClass;
9
10
/**
11
 * @group 6884
12
 */
13
final class GH6884Test extends OrmFunctionalTestCase
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected function setUp(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
19
    {
20
        parent::setUp();
21
22
        $this->_schemaTool->createSchema(
0 ignored issues
show
Bug introduced by
The property _schemaTool does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6884Test. Did you mean schemaTool?
Loading history...
23
            [
0 ignored issues
show
Coding Style introduced by
Multi-line array contains a single value; use single-line array instead
Loading history...
24
                $this->_em->getClassMetadata(GH6884Person::class)
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6884Test. Did you maybe forget to declare it?
Loading history...
introduced by
Multiline arrays must have a trailing comma after the last element.
Loading history...
25
            ]
26
        );
27
28
        $listener = $this->createPartialMock(stdClass::class, ['preUpdate']);
29
30
        $listener->expects($this->exactly(3))->method('preUpdate');
31
32
        $this->_em->getEventManager()->addEventListener([Events::preUpdate], $listener);
33
34
        $this->_em->getClassMetadata(GH6884Person::class)
35
                  ->addEntityListener(Events::postUpdate, GH6884Person::class, 'onPostUpdate');
36
    }
37
38
    public function testIssue(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
39
    {
40
        $person  = new GH6884Person();
41
        $person2 = new GH6884Person();
42
43
        $this->_em->persist($person);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6884Test. Did you maybe forget to declare it?
Loading history...
44
        $this->_em->persist($person2);
45
        $this->_em->flush();
46
47
        $person->isAlive  = true;
48
        $person2->isAlive = true;
49
50
        $this->_em->flush();
51
    }
52
}
53
54
/**
55
 * @Entity()
56
 */
57
class GH6884Person
58
{
59
    /** @Id() @Column(type="integer") @GeneratedValue() */
60
    public $id;
61
62
    /** @Column(type="boolean", nullable=false) */
63
    public $isAlive = false;
64
65
    /** @var bool */
66
    public $nonOrmProperty = false;
67
68
    public function onPostUpdate(GH6884Person $person, LifecycleEventArgs $eventArgs): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
69
    {
70
        $person->nonOrmProperty = true;
71
72
        $eventArgs->getEntityManager()->flush();
73
    }
74
}
75