@@ -616,6 +616,45 @@ public function testTableComment()
616
616
$ this ->assertEquals (['comment on table "posts" is \'Look at my comment, it is amazing \'' ], $ getSql ('Postgres ' ));
617
617
}
618
618
619
+ public function testColumnDefault ()
620
+ {
621
+ // Test a normal string literal column default.
622
+ $ getSql = function ($ grammar ) {
623
+ return $ this ->getBlueprint ($ grammar , 'posts ' , function ($ table ) {
624
+ $ table ->tinyText ('note ' )->default ('this will work ' );
625
+ })->toSql ();
626
+ };
627
+
628
+ $ this ->assertEquals (['alter table `posts` add `note` tinytext not null default \'this will work \'' ], $ getSql ('MySql ' ));
629
+
630
+ // Test a string literal column default containing an apostrophe (#56124)
631
+ $ getSql = function ($ grammar ) {
632
+ return $ this ->getBlueprint ($ grammar , 'posts ' , function ($ table ) {
633
+ $ table ->tinyText ('note ' )->default ('this \'ll work too ' );
634
+ })->toSql ();
635
+ };
636
+
637
+ $ this ->assertEquals (['alter table `posts` add `note` tinytext not null default \'this \'\'ll work too \'' ], $ getSql ('MySql ' ));
638
+
639
+ // Test a backed enumeration column default
640
+ $ getSql = function ($ grammar ) {
641
+ return $ this ->getBlueprint ($ grammar , 'posts ' , function ($ table ) {
642
+ $ enum = ApostropheBackedEnum::ValueWithoutApostrophe;
643
+ $ table ->tinyText ('note ' )->default ($ enum );
644
+ })->toSql ();
645
+ };
646
+ $ this ->assertEquals (['alter table `posts` add `note` tinytext not null default \'this will work \'' ], $ getSql ('MySql ' ));
647
+
648
+ // Test a backed enumeration column default containing an apostrophe (#56124)
649
+ $ getSql = function ($ grammar ) {
650
+ return $ this ->getBlueprint ($ grammar , 'posts ' , function ($ table ) {
651
+ $ enum = ApostropheBackedEnum::ValueWithApostrophe;
652
+ $ table ->tinyText ('note ' )->default ($ enum );
653
+ })->toSql ();
654
+ };
655
+ $ this ->assertEquals (['alter table `posts` add `note` tinytext not null default \'this \'\'ll work too \'' ], $ getSql ('MySql ' ));
656
+ }
657
+
619
658
protected function getConnection (?string $ grammar = null , string $ prefix = '' )
620
659
{
621
660
$ connection = m::mock (Connection::class)
@@ -652,3 +691,9 @@ protected function getBlueprint(
652
691
return new Blueprint ($ connection , $ table , $ callback );
653
692
}
654
693
}
694
+
695
+ enum ApostropheBackedEnum: string
696
+ {
697
+ case ValueWithoutApostrophe = 'this will work ' ;
698
+ case ValueWithApostrophe = 'this \'ll work too ' ;
699
+ }
0 commit comments