From ab5e9e393b94bfcf851d4f4188298f7e1c47479e Mon Sep 17 00:00:00 2001 From: Rok Motaln Date: Sun, 3 Mar 2024 16:02:48 +0100 Subject: [PATCH 1/3] Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (#11314) * Fix loading SchemaTool::getSchemaFromMetadata() uniqueConstraint without a name Fixes a type miss-match exception when reading a UniqueConstraint defined on an Entity which doesn't have a predefined name. * Fix deprecation on DBAL 3 --------- Co-authored-by: Alexander M. Turek --- src/Tools/SchemaTool.php | 2 +- tests/Tests/ORM/Tools/SchemaToolTest.php | 47 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Tools/SchemaTool.php b/src/Tools/SchemaTool.php index 2e02279cc0c..532d40d82a9 100644 --- a/src/Tools/SchemaTool.php +++ b/src/Tools/SchemaTool.php @@ -365,7 +365,7 @@ static function (ClassMetadata $class) use ($idMapping): bool { if (isset($class->table['uniqueConstraints'])) { foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) { - $uniqIndex = new Index($indexName, $this->getIndexColumns($class, $indexData), true, false, [], $indexData['options'] ?? []); + $uniqIndex = new Index('tmp__' . $indexName, $this->getIndexColumns($class, $indexData), true, false, [], $indexData['options'] ?? []); foreach ($table->getIndexes() as $tableIndexName => $tableIndex) { $method = method_exists($tableIndex, 'isFulfilledBy') ? 'isFulfilledBy' : 'isFullfilledBy'; diff --git a/tests/Tests/ORM/Tools/SchemaToolTest.php b/tests/Tests/ORM/Tools/SchemaToolTest.php index 83f70e85965..bc0e811f68f 100644 --- a/tests/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Tests/ORM/Tools/SchemaToolTest.php @@ -374,6 +374,27 @@ public function testConfigurationSchemaIgnoredEntity(): void self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.'); self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.'); } + + #[Group('11314')] + public function testLoadUniqueConstraintWithoutName(): void + { + $em = $this->getTestEntityManager(); + $entity = $em->getClassMetadata(GH11314Entity::class); + + $schemaTool = new SchemaTool($em); + $schema = $schemaTool->getSchemaFromMetadata([$entity]); + + self::assertTrue($schema->hasTable('GH11314Entity')); + + $tableEntity = $schema->getTable('GH11314Entity'); + + self::assertTrue($tableEntity->hasIndex('uniq_2d81a3ed5bf54558875f7fd5')); + + $tableIndex = $tableEntity->getIndex('uniq_2d81a3ed5bf54558875f7fd5'); + + self::assertTrue($tableIndex->isUnique()); + self::assertSame(['field', 'anotherField'], $tableIndex->getColumns()); + } } /** @@ -559,6 +580,32 @@ class IndexByFieldEntity public $fieldName; } +/** + * @Entity + * @Table(uniqueConstraints={@UniqueConstraint(columns={"field", "anotherField"})}) + */ +class GH11314Entity +{ + /** + * @Column(type="integer") + * @Id + * @var int + */ + private $id; + + /** + * @Column(name="field", type="string") + * @var string + */ + private $field; + + /** + * @Column(name="anotherField", type="string") + * @var string + */ + private $anotherField; +} + class IncorrectIndexByFieldEntity { /** @var int */ From 21221f73cc85d7c09a43dc42f28882a65cb0219e Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 3 Mar 2024 16:46:12 +0100 Subject: [PATCH 2/3] Bump CI workflows (#11336) --- .github/workflows/continuous-integration.yml | 14 +++++++------- .github/workflows/documentation.yml | 2 +- .github/workflows/release-on-milestone-closed.yml | 2 +- .github/workflows/static-analysis.yml | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 695c299d379..ab98943cc3d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -97,9 +97,9 @@ jobs: ORM_PROXY_IMPLEMENTATION: "${{ matrix.proxy }}" - name: "Upload coverage file" - uses: "actions/upload-artifact@v3" + uses: "actions/upload-artifact@v4" with: - name: "phpunit-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-coverage" + name: "phpunit-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-${{ matrix.proxy }}-coverage" path: "coverage*.xml" @@ -170,9 +170,9 @@ jobs: run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_pgsql.xml --coverage-clover=coverage.xml" - name: "Upload coverage file" - uses: "actions/upload-artifact@v3" + uses: "actions/upload-artifact@v4" with: - name: "${{ github.job }}-${{ matrix.postgres-version }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-coverage" + name: "${{ github.job }}-${{ matrix.postgres-version }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-${{ matrix.extension }}-coverage" path: "coverage.xml" @@ -240,7 +240,7 @@ jobs: run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml" - name: "Upload coverage file" - uses: "actions/upload-artifact@v3" + uses: "actions/upload-artifact@v4" with: name: "${{ github.job }}-${{ matrix.mariadb-version }}-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-coverage" path: "coverage.xml" @@ -317,7 +317,7 @@ jobs: ENABLE_SECOND_LEVEL_CACHE: 1 - name: "Upload coverage files" - uses: "actions/upload-artifact@v3" + uses: "actions/upload-artifact@v4" with: name: "${{ github.job }}-${{ matrix.mysql-version }}-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-coverage" path: "coverage*.xml" @@ -372,7 +372,7 @@ jobs: fetch-depth: 2 - name: "Download coverage files" - uses: "actions/download-artifact@v3" + uses: "actions/download-artifact@v4" with: path: "reports" diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index f0bbf5b9e2a..bd9ebea8d28 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -27,7 +27,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "none" - php-version: "8.2" + php-version: "8.3" - name: "Remove existing composer file" run: "rm composer.json" diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index c4389142616..d46dc4c36bb 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -7,7 +7,7 @@ on: jobs: release: - uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@3.0.0" + uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@4.0.0" secrets: GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 88b7196e357..a8765e23299 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -48,7 +48,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "none" - php-version: "8.2" + php-version: "8.3" - name: "Require specific DBAL version" run: "composer require doctrine/dbal ^${{ matrix.dbal-version }} --no-update" @@ -89,7 +89,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "none" - php-version: "8.2" + php-version: "8.3" - name: "Require specific persistence version" run: "composer require doctrine/persistence ^3.1 --no-update" From e3e96745cc2b1cbf4040b40a60949779eeaabdc9 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 3 Mar 2024 16:49:00 +0100 Subject: [PATCH 3/3] Fix annotation --- tests/Tests/ORM/Tools/SchemaToolTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Tests/ORM/Tools/SchemaToolTest.php b/tests/Tests/ORM/Tools/SchemaToolTest.php index bc0e811f68f..a3726f2d0b7 100644 --- a/tests/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Tests/ORM/Tools/SchemaToolTest.php @@ -375,7 +375,7 @@ public function testConfigurationSchemaIgnoredEntity(): void self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.'); } - #[Group('11314')] + /** @group GH-11314 */ public function testLoadUniqueConstraintWithoutName(): void { $em = $this->getTestEntityManager();