@@ -872,23 +872,87 @@ public function testAddingJsonb()
872
872
873
873
public function testAddingDate ()
874
874
{
875
- $ blueprint = new Blueprint ($ this ->getConnection (), 'users ' );
875
+ $ conn = $ this ->getConnection ();
876
+ $ conn ->shouldReceive ('isMaria ' )->andReturn (false );
877
+ $ conn ->shouldReceive ('getServerVersion ' )->andReturn ('8.0.13 ' );
878
+
879
+ $ blueprint = new Blueprint ($ conn , 'users ' );
876
880
$ blueprint ->date ('foo ' );
877
881
$ statements = $ blueprint ->toSql ();
878
882
879
883
$ this ->assertCount (1 , $ statements );
880
884
$ this ->assertSame ('alter table `users` add `foo` date not null ' , $ statements [0 ]);
881
885
}
882
886
887
+ public function testAddingDateWithDefaultCurrent ()
888
+ {
889
+ $ conn = $ this ->getConnection ();
890
+ $ conn ->shouldReceive ('isMaria ' )->andReturn (false );
891
+ $ conn ->shouldReceive ('getServerVersion ' )->andReturn ('8.0.13 ' );
892
+
893
+ $ blueprint = new Blueprint ($ conn , 'users ' );
894
+ $ blueprint ->date ('foo ' )->useCurrent ();
895
+ $ statements = $ blueprint ->toSql ();
896
+
897
+ $ this ->assertCount (1 , $ statements );
898
+ $ this ->assertSame ('alter table `users` add `foo` date not null default (CURDATE()) ' , $ statements [0 ]);
899
+ }
900
+
901
+ public function testAddingDateWithDefaultCurrentOn57 ()
902
+ {
903
+ $ conn = $ this ->getConnection ();
904
+ $ conn ->shouldReceive ('isMaria ' )->andReturn (false );
905
+ $ conn ->shouldReceive ('getServerVersion ' )->andReturn ('5.7 ' );
906
+
907
+ $ blueprint = new Blueprint ($ conn , 'users ' );
908
+ $ blueprint ->date ('foo ' )->useCurrent ();
909
+ $ statements = $ blueprint ->toSql ();
910
+
911
+ $ this ->assertCount (1 , $ statements );
912
+ $ this ->assertSame ('alter table `users` add `foo` date not null ' , $ statements [0 ]);
913
+ }
914
+
883
915
public function testAddingYear ()
884
916
{
885
- $ blueprint = new Blueprint ($ this ->getConnection (), 'users ' );
917
+ $ conn = $ this ->getConnection ();
918
+ $ conn ->shouldReceive ('isMaria ' )->andReturn (false );
919
+ $ conn ->shouldReceive ('getServerVersion ' )->andReturn ('8.0.13 ' );
920
+
921
+ $ blueprint = new Blueprint ($ conn , 'users ' );
886
922
$ blueprint ->year ('birth_year ' );
887
923
$ statements = $ blueprint ->toSql ();
888
924
$ this ->assertCount (1 , $ statements );
889
925
$ this ->assertSame ('alter table `users` add `birth_year` year not null ' , $ statements [0 ]);
890
926
}
891
927
928
+ public function testAddingYearWithDefaultCurrent ()
929
+ {
930
+ $ conn = $ this ->getConnection ();
931
+ $ conn ->shouldReceive ('isMaria ' )->andReturn (false );
932
+ $ conn ->shouldReceive ('getServerVersion ' )->andReturn ('8.0.13 ' );
933
+
934
+ $ blueprint = new Blueprint ($ conn , 'users ' );
935
+ $ blueprint ->year ('birth_year ' )->useCurrent ();
936
+ $ statements = $ blueprint ->toSql ();
937
+
938
+ $ this ->assertCount (1 , $ statements );
939
+ $ this ->assertSame ('alter table `users` add `birth_year` year not null default (YEAR(CURDATE())) ' , $ statements [0 ]);
940
+ }
941
+
942
+ public function testAddingYearWithDefaultCurrentOn57 ()
943
+ {
944
+ $ conn = $ this ->getConnection ();
945
+ $ conn ->shouldReceive ('isMaria ' )->andReturn (false );
946
+ $ conn ->shouldReceive ('getServerVersion ' )->andReturn ('5.7 ' );
947
+
948
+ $ blueprint = new Blueprint ($ conn , 'users ' );
949
+ $ blueprint ->year ('birth_year ' )->useCurrent ();
950
+ $ statements = $ blueprint ->toSql ();
951
+
952
+ $ this ->assertCount (1 , $ statements );
953
+ $ this ->assertSame ('alter table `users` add `birth_year` year not null ' , $ statements [0 ]);
954
+ }
955
+
892
956
public function testAddingDateTime ()
893
957
{
894
958
$ blueprint = new Blueprint ($ this ->getConnection (), 'users ' );
0 commit comments