File: GH10880Test.php

package info (click to toggle)
doctrine 3.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,556 kB
  • sloc: php: 108,620; xml: 1,340; makefile: 35; sh: 14
file content (103 lines) | stat: -rw-r--r-- 2,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

use function reset;

class GH10880Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEntitySchema([
            GH10880BaseProcess::class,
            GH10880Process::class,
            GH10880ProcessOwner::class,
        ]);
    }

    public function testProcessShouldBeUpdated(): void
    {
        $process              = new GH10880Process();
        $process->description = 'first value';

        $owner          = new GH10880ProcessOwner();
        $owner->process = $process;

        $this->_em->persist($process);
        $this->_em->persist($owner);
        $this->_em->flush();
        $this->_em->clear();

        $ownerLoaded                       = $this->_em->getRepository(GH10880ProcessOwner::class)->find($owner->id);
        $ownerLoaded->process->description = 'other description';

        $queryLog = $this->getQueryLog();
        $queryLog->reset()->enable();
        $this->_em->flush();

        $this->removeTransactionCommandsFromQueryLog();

        self::assertCount(1, $queryLog->queries);
        $query = reset($queryLog->queries);
        self::assertSame('UPDATE GH10880BaseProcess SET description = ? WHERE id = ?', $query['sql']);
    }

    private function removeTransactionCommandsFromQueryLog(): void
    {
        $log = $this->getQueryLog();

        foreach ($log->queries as $key => $entry) {
            if ($entry['sql'] === '"START TRANSACTION"' || $entry['sql'] === '"COMMIT"') {
                unset($log->queries[$key]);
            }
        }
    }
}

#[ORM\Entity]
class GH10880ProcessOwner
{
    /** @var int */
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    public $id;

    /**
     * fetch=EAGER is important to reach the part of \Doctrine\ORM\UnitOfWork::createEntity()
     * that is important for this regression test
     *
     * @var GH10880Process
     */
    #[ORM\ManyToOne(targetEntity: GH10880Process::class, fetch: 'EAGER')]
    public $process;
}

#[ORM\Entity]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap(['process' => GH10880Process::class])]
abstract class GH10880BaseProcess
{
    /** @var int */
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    public $id;

    /** @var string */
    #[ORM\Column(type: 'text')]
    public $description;
}

#[ORM\Entity]
class GH10880Process extends GH10880BaseProcess
{
}