88use Doctrine \DBAL \Platforms \PostgreSQLPlatform ;
99use Doctrine \DBAL \Platforms \SQLServerPlatform ;
1010use Doctrine \DBAL \Schema \AbstractSchemaManager ;
11+ use Doctrine \DBAL \Schema \Name \Identifier ;
12+ use Doctrine \DBAL \Schema \Name \UnqualifiedName ;
13+ use Doctrine \DBAL \Schema \PrimaryKeyConstraint ;
1114use Doctrine \DBAL \Schema \Table ;
1215use PHPUnit \Framework \Attributes \Group ;
1316
1417use function array_change_key_case ;
18+ use function class_exists ;
1519use function count ;
1620use function strtolower ;
1721
@@ -36,12 +40,24 @@ public function testIssue2059(): void
3640 {
3741 $ user = new Table ('ddc2059_user ' );
3842 $ user ->addColumn ('id ' , 'integer ' );
39- $ user ->setPrimaryKey (['id ' ]);
43+
44+ if (class_exists (PrimaryKeyConstraint::class)) {
45+ $ user ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
46+ } else {
47+ $ user ->setPrimaryKey (['id ' ]);
48+ }
49+
4050 $ project = new Table ('ddc2059_project ' );
4151 $ project ->addColumn ('id ' , 'integer ' );
4252 $ project ->addColumn ('user_id ' , 'integer ' );
4353 $ project ->addColumn ('user ' , 'string ' );
44- $ project ->setPrimaryKey (['id ' ]);
54+
55+ if (class_exists (PrimaryKeyConstraint::class)) {
56+ $ project ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
57+ } else {
58+ $ project ->setPrimaryKey (['id ' ]);
59+ }
60+
4561 $ project ->addForeignKeyConstraint ('ddc2059_user ' , ['user_id ' ], ['id ' ]);
4662
4763 $ metadata = $ this ->convertToClassMetadata ([$ project , $ user ], []);
@@ -54,7 +70,13 @@ public function testLoadMetadataFromDatabase(): void
5470 {
5571 $ table = new Table ('dbdriver_foo ' );
5672 $ table ->addColumn ('id ' , 'integer ' );
57- $ table ->setPrimaryKey (['id ' ]);
73+
74+ if (class_exists (PrimaryKeyConstraint::class)) {
75+ $ table ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
76+ } else {
77+ $ table ->setPrimaryKey (['id ' ]);
78+ }
79+
5880 $ table ->addColumn ('bar ' , 'string ' , ['notnull ' => false , 'length ' => 200 ]);
5981
6082 $ this ->dropAndCreateTable ($ table );
@@ -81,13 +103,24 @@ public function testLoadMetadataWithForeignKeyFromDatabase(): void
81103 {
82104 $ tableB = new Table ('dbdriver_bar ' );
83105 $ tableB ->addColumn ('id ' , 'integer ' );
84- $ tableB ->setPrimaryKey (['id ' ]);
106+
107+ if (class_exists (PrimaryKeyConstraint::class)) {
108+ $ tableB ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
109+ } else {
110+ $ tableB ->setPrimaryKey (['id ' ]);
111+ }
85112
86113 $ this ->dropAndCreateTable ($ tableB );
87114
88115 $ tableA = new Table ('dbdriver_baz ' );
89116 $ tableA ->addColumn ('id ' , 'integer ' );
90- $ tableA ->setPrimaryKey (['id ' ]);
117+
118+ if (class_exists (PrimaryKeyConstraint::class)) {
119+ $ tableA ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
120+ } else {
121+ $ tableA ->setPrimaryKey (['id ' ]);
122+ }
123+
91124 $ tableA ->addColumn ('bar_id ' , 'integer ' );
92125 $ tableA ->addForeignKeyConstraint ('dbdriver_bar ' , ['bar_id ' ], ['id ' ]);
93126
@@ -127,11 +160,21 @@ public function testIgnoreManyToManyTableWithoutFurtherForeignKeyDetails(): void
127160 {
128161 $ tableB = new Table ('dbdriver_bar ' );
129162 $ tableB ->addColumn ('id ' , 'integer ' );
130- $ tableB ->setPrimaryKey (['id ' ]);
163+
164+ if (class_exists (PrimaryKeyConstraint::class)) {
165+ $ tableB ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
166+ } else {
167+ $ tableB ->setPrimaryKey (['id ' ]);
168+ }
131169
132170 $ tableA = new Table ('dbdriver_baz ' );
133171 $ tableA ->addColumn ('id ' , 'integer ' );
134- $ tableA ->setPrimaryKey (['id ' ]);
172+
173+ if (class_exists (PrimaryKeyConstraint::class)) {
174+ $ tableA ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
175+ } else {
176+ $ tableA ->setPrimaryKey (['id ' ]);
177+ }
135178
136179 $ tableMany = new Table ('dbdriver_bar_baz ' );
137180 $ tableMany ->addColumn ('bar_id ' , 'integer ' );
@@ -148,7 +191,13 @@ public function testLoadMetadataFromDatabaseDetail(): void
148191 $ table = new Table ('dbdriver_foo ' );
149192
150193 $ table ->addColumn ('id ' , 'integer ' , ['unsigned ' => true ]);
151- $ table ->setPrimaryKey (['id ' ]);
194+
195+ if (class_exists (PrimaryKeyConstraint::class)) {
196+ $ table ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
197+ } else {
198+ $ table ->setPrimaryKey (['id ' ]);
199+ }
200+
152201 $ table ->addColumn ('column_unsigned ' , 'integer ' , ['unsigned ' => true ]);
153202 $ table ->addColumn ('column_comment ' , 'string ' , ['length ' => 16 , 'comment ' => 'test_comment ' ]);
154203 $ table ->addColumn ('column_default ' , 'string ' , ['length ' => 16 , 'default ' => 'test_default ' ]);
0 commit comments