-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathGH12017Test.php
More file actions
118 lines (96 loc) · 2.98 KB
/
Copy pathGH12017Test.php
File metadata and controls
118 lines (96 loc) · 2.98 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;
class GH12017Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->createSchemaForModels(GH12017Entity::class, GH12017EntityWithStringField::class);
}
public function testGeneratedFieldShouldNotBeDetectedAsChangeAfterFlush(): void
{
$entity = new GH12017Entity();
$this->_em->persist($entity);
$this->_em->flush();
$uow = $this->_em->getUnitOfWork();
$uow->computeChangeSets();
self::assertFalse(
$uow->isScheduledForUpdate($entity),
'Entity should not be scheduled for update after a generated field was refreshed from the DB',
);
}
public function testGeneratedStringFieldShouldNotBeDetectedAsChangeAfterFlush(): void
{
$entity = new GH12017EntityWithStringField();
$this->_em->persist($entity);
$this->_em->flush();
$uow = $this->_em->getUnitOfWork();
$uow->computeChangeSets();
self::assertFalse(
$uow->isScheduledForUpdate($entity),
'Entity should not be scheduled for update after a generated string field was refreshed from the DB',
);
}
public function testGeneratedFieldShouldNotBeDetectedAsChangeAfterUpdate(): void
{
$entity = new GH12017Entity();
$this->_em->persist($entity);
$this->_em->flush();
$this->_em->clear();
$entity = $this->_em->find(GH12017Entity::class, $entity->id);
$entity->other = 1;
$this->_em->flush();
$uow = $this->_em->getUnitOfWork();
$uow->computeChangeSets();
self::assertFalse(
$uow->isScheduledForUpdate($entity),
'Entity should not be scheduled for update after a generated field was refreshed from the DB',
);
}
}
#[ORM\Entity]
#[ORM\Table(name: 'gh12017')]
class GH12017Entity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public int|null $id = null;
#[ORM\Column(
type: Types::DATETIME_IMMUTABLE,
nullable: false,
insertable: false,
updatable: false,
options: ['default' => 'CURRENT_TIMESTAMP'],
generated: 'ALWAYS',
)]
public DateTimeImmutable|null $tested = null;
#[ORM\Column(
type: Types::INTEGER,
nullable: false,
options: ['default' => 0],
)]
public int $other = 0;
}
#[ORM\Entity]
#[ORM\Table(name: 'gh12017_string')]
class GH12017EntityWithStringField
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public int|null $id = null;
#[ORM\Column(
type: Types::STRING,
insertable: false,
updatable: false,
options: ['default' => 'generated'],
generated: 'ALWAYS',
)]
public string|null $tested = null;
}