From 657a30f8ceef2a78c2ff36a9fe6c6a6717c1c448 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 1 Apr 2021 23:16:53 +0200 Subject: [PATCH 1/2] [GH-6394] Bugfix: IdentifierFlattener support for association non-object values. (#8384) * [GH-6394] Bugfix: IdentifierFlattener support for association non-object values * [GH-6394] Bugfix: BasicEntityPersister::update used wrong identifiers for version assignment. * Exclude MissingNativeTypeHint phpcs rule as 7.4 is not lowest version. --- .../Entity/BasicEntityPersister.php | 2 +- phpcs.xml.dist | 1 + .../ORM/Functional/Ticket/GH6394Test.php | 103 ++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 9e17c7e214f..adbd5934b43 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -400,7 +400,7 @@ public function update($entity) $this->updateTable($entity, $quotedTableName, $data, $isVersioned); if ($isVersioned) { - $id = $this->em->getUnitOfWork()->getEntityIdentifier($entity); + $id = $this->class->getIdentifierValues($entity); $this->assignDefaultVersionValue($entity, $id); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 8b226ebb15a..821a7c499da 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -22,6 +22,7 @@ + diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php new file mode 100644 index 00000000000..8a31c65d4c9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php @@ -0,0 +1,103 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(A::class), + $this->_em->getClassMetadata(B::class), + ] + ); + } + + /** + * Test the the version of an entity can be fetched, when the id field and + * the id column are different. + * + * @group 6393 + */ + public function testFetchVersionValueForDifferentIdFieldAndColumn(): void + { + $a = new A(1); + $this->_em->persist($a); + + $b = new B($a, 'foo'); + $this->_em->persist($b); + $this->_em->flush(); + + self::assertSame(1, $b->version); + + $b->something = 'bar'; + $this->_em->flush(); + + self::assertSame(2, $b->version); + } +} + +/** + * @Entity + */ +class A +{ + /** + * @Id + * @Column(type="integer") + * @var int + */ + public $id; + + /** + * @Version + * @Column(type="integer") + * @var int + */ + public $version; + + public function __construct(int $id) + { + $this->id = $id; + } +} + +/** + * @Entity + */ +class B +{ + /** + * @Id + * @ManyToOne(targetEntity="A") + * @JoinColumn(name="aid", referencedColumnName="id") + * @var A + */ + public $a; + + /** + * @Column(type="string") + * @var string + */ + public $something; + + /** + * @Version + * @Column(type="integer") + * @var int + */ + public $version; + + public function __construct(A $a, string $something) + { + $this->a = $a; + $this->something = $something; + } +} From 961da8b0cc058d92851f585308adf4c0bfcc94fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 1 Apr 2021 23:32:04 +0200 Subject: [PATCH 2/2] Synchronize static analysis jobs with upstream --- .github/workflows/static-analysis.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 98b66796322..620f292f44f 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,12 +1,18 @@ -name: Static Analysis + +name: "Static Analysis" on: pull_request: + branches: + - "*.x" + push: + branches: + - "*.x" jobs: static-analysis-phpstan: - name: "PHPStan" - runs-on: "ubuntu-latest" + name: "Static Analysis with PHPStan" + runs-on: "ubuntu-20.04" strategy: matrix: @@ -22,17 +28,18 @@ jobs: with: coverage: "none" php-version: "${{ matrix.php-version }}" - tools: cs2pr - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" + with: + dependency-versions: "highest" - name: "Run a static analysis with phpstan/phpstan" - run: "php vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr" + run: "vendor/bin/phpstan analyse" static-analysis-psalm: - name: "Psalm" - runs-on: "ubuntu-latest" + name: "Static Analysis with Psalm" + runs-on: "ubuntu-20.04" strategy: matrix: @@ -51,6 +58,8 @@ jobs: - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" + with: + dependency-versions: "highest" - name: "Run a static analysis with vimeo/psalm" run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)"