|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 6 | + |
| 7 | +use DateTimeImmutable; |
| 8 | +use Doctrine\DBAL\Schema\DefaultExpression\CurrentTimestamp; |
| 9 | +use Doctrine\DBAL\Types\Types; |
| 10 | +use Doctrine\ORM\Mapping as ORM; |
| 11 | +use Doctrine\ORM\Mapping\DiscriminatorColumn; |
| 12 | +use Doctrine\ORM\Mapping\DiscriminatorMap; |
| 13 | +use Doctrine\ORM\Mapping\InheritanceType; |
| 14 | +use Doctrine\Tests\OrmFunctionalTestCase; |
| 15 | + |
| 16 | +class GH12017SubClassTest extends OrmFunctionalTestCase |
| 17 | +{ |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + parent::setUp(); |
| 21 | + |
| 22 | + $this->createSchemaForModels(GH12017ParentEntity::class, GH12017ChildEntity::class); |
| 23 | + } |
| 24 | + |
| 25 | + public function testGeneratedFieldFromChildShouldNotBeDetectedAsChangeAfterInsert(): void |
| 26 | + { |
| 27 | + $entity = new GH12017ChildEntity(); |
| 28 | + |
| 29 | + $this->_em->persist($entity); |
| 30 | + $this->_em->flush(); |
| 31 | + |
| 32 | + $uow = $this->_em->getUnitOfWork(); |
| 33 | + $uow->computeChangeSets(); |
| 34 | + |
| 35 | + self::assertFalse( |
| 36 | + $uow->isScheduledForUpdate($entity), |
| 37 | + 'Entity should not be scheduled for update after a generated field was refreshed from the DB', |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + public function testGeneratedStringFieldShouldNotBeDetectedAsChangeAfterInsert(): void |
| 42 | + { |
| 43 | + $entity = new GH12017ChildEntity(); |
| 44 | + $this->_em->persist($entity); |
| 45 | + $this->_em->flush(); |
| 46 | + |
| 47 | + $uow = $this->_em->getUnitOfWork(); |
| 48 | + $uow->computeChangeSets(); |
| 49 | + |
| 50 | + self::assertFalse( |
| 51 | + $uow->isScheduledForUpdate($entity), |
| 52 | + 'Entity should not be scheduled for update after a generated string field was refreshed from the DB', |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGeneratedFieldShouldNotBeDetectedAsChangeAfterUpdate(): void |
| 57 | + { |
| 58 | + $entity = new GH12017ChildEntity(); |
| 59 | + $this->_em->persist($entity); |
| 60 | + $this->_em->flush(); |
| 61 | + |
| 62 | + $entity->other = 1; |
| 63 | + $this->_em->flush(); |
| 64 | + |
| 65 | + $uow = $this->_em->getUnitOfWork(); |
| 66 | + $uow->computeChangeSets(); |
| 67 | + self::assertFalse( |
| 68 | + $uow->isScheduledForUpdate($entity), |
| 69 | + 'Entity should not be scheduled for update after a generated field was refreshed from the DB', |
| 70 | + ); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +#[ORM\MappedSuperclass] |
| 75 | +#[InheritanceType('JOINED')] |
| 76 | +#[DiscriminatorColumn(name: 'discr', type: 'string')] |
| 77 | +#[DiscriminatorMap(['child' => GH12017ChildEntity::class])] |
| 78 | +#[ORM\Entity] |
| 79 | +#[ORM\Table(name: 'gh12017_parent')] |
| 80 | +class GH12017ParentEntity |
| 81 | +{ |
| 82 | + #[ORM\Id] |
| 83 | + #[ORM\GeneratedValue] |
| 84 | + #[ORM\Column] |
| 85 | + public int $id; |
| 86 | + |
| 87 | + #[ORM\Column( |
| 88 | + type: Types::INTEGER, |
| 89 | + nullable: false, |
| 90 | + options: ['default' => 0], |
| 91 | + )] |
| 92 | + public int $other = 0; |
| 93 | +} |
| 94 | + |
| 95 | +#[ORM\Entity] |
| 96 | +#[ORM\Table(name: 'gh12017_child')] |
| 97 | +class GH12017ChildEntity extends GH12017ParentEntity |
| 98 | +{ |
| 99 | + #[ORM\Column( |
| 100 | + type: Types::DATETIME_IMMUTABLE, |
| 101 | + insertable: false, |
| 102 | + updatable: false, |
| 103 | + options: ['default' => new CurrentTimestamp()], |
| 104 | + generated: 'ALWAYS', |
| 105 | + )] |
| 106 | + public DateTimeImmutable|null $tested = null; |
| 107 | +} |
0 commit comments