@@ -278,6 +278,64 @@ public function testSetDiscriminatorColumnWithoutLength(): void
278278 self ::assertEquals (255 , $ column ->getLength ());
279279 }
280280
281+ public function testSetDefaultStringLength (): void
282+ {
283+ $ em = $ this ->getTestEntityManager ();
284+ $ em ->getConfiguration ()->setDefaultStringTypeSchemaLength (191 );
285+ $ schemaTool = new SchemaTool ($ em );
286+ $ metadata = $ em ->getClassMetadata (FirstEntity::class);
287+
288+ $ schema = $ schemaTool ->getSchemaFromMetadata ([$ metadata ]);
289+
290+ self ::assertTrue ($ schema ->hasTable ('first_entity ' ));
291+ $ table = $ schema ->getTable ('first_entity ' );
292+
293+ self ::assertTrue ($ table ->hasColumn ('name ' ));
294+ $ column = $ table ->getColumn ('name ' );
295+
296+ self ::assertEquals (191 , $ column ->getLength ());
297+ }
298+
299+ public function testSetDefaultStringLengthDoesNotOverrideExplicitLength (): void
300+ {
301+ $ em = $ this ->getTestEntityManager ();
302+ $ em ->getConfiguration ()->setDefaultStringTypeSchemaLength (191 );
303+ $ schemaTool = new SchemaTool ($ em );
304+ $ metadata = $ em ->getClassMetadata (FirstEntity::class);
305+ $ metadata ->fieldMappings ['name ' ]->length = 32 ;
306+
307+ $ schema = $ schemaTool ->getSchemaFromMetadata ([$ metadata ]);
308+
309+ self ::assertTrue ($ schema ->hasTable ('first_entity ' ));
310+ $ table = $ schema ->getTable ('first_entity ' );
311+
312+ self ::assertTrue ($ table ->hasColumn ('name ' ));
313+ $ column = $ table ->getColumn ('name ' );
314+
315+ self ::assertEquals (32 , $ column ->getLength ());
316+ }
317+
318+ public function testSetDiscriminatorColumnWithCustomDefaultLength (): void
319+ {
320+ $ em = $ this ->getTestEntityManager ();
321+ $ em ->getConfiguration ()->setDefaultStringTypeSchemaLength (191 );
322+ $ schemaTool = new SchemaTool ($ em );
323+ $ metadata = $ em ->getClassMetadata (FirstEntity::class);
324+
325+ $ metadata ->setInheritanceType (ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE );
326+ $ metadata ->setDiscriminatorColumn (['name ' => 'discriminator ' , 'type ' => 'string ' ]);
327+
328+ $ schema = $ schemaTool ->getSchemaFromMetadata ([$ metadata ]);
329+
330+ self ::assertTrue ($ schema ->hasTable ('first_entity ' ));
331+ $ table = $ schema ->getTable ('first_entity ' );
332+
333+ self ::assertTrue ($ table ->hasColumn ('discriminator ' ));
334+ $ column = $ table ->getColumn ('discriminator ' );
335+
336+ self ::assertEquals (191 , $ column ->getLength ());
337+ }
338+
281339 public function testSetDiscriminatorColumnWithEnumType (): void
282340 {
283341 if (! class_exists (EnumType::class)) {
0 commit comments