7
7
8
8
namespace Tests \KitLoong \Feature \PgSQL ;
9
9
10
+ use Illuminate \Support \Facades \DB ;
10
11
use Illuminate \Support \Facades \File ;
11
12
use Illuminate \Support \Str ;
12
13
@@ -16,13 +17,28 @@ public function testRun()
16
17
{
17
18
$ migrateTemplates = function () {
18
19
$ this ->migrateGeneral ('pgsql ' );
20
+
21
+ // Test timestamp default now()
22
+ DB ::statement ("ALTER TABLE all_columns_pgsql ADD COLUMN timestamp_defaultnow timestamp(0) without time zone DEFAULT now() NOT NULL " );
19
23
};
20
24
21
25
$ generateMigrations = function () {
22
26
$ this ->generateMigrations ();
23
27
};
24
28
25
- $ this ->verify ($ migrateTemplates , $ generateMigrations );
29
+ $ beforeVerify = function () {
30
+ $ this ->assertLineExistsThenReplace (
31
+ $ this ->storageSql ('actual.sql ' ),
32
+ 'timestamp_defaultnow timestamp(0) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL '
33
+ );
34
+
35
+ $ this ->assertLineExistsThenReplace (
36
+ $ this ->storageSql ('expected.sql ' ),
37
+ 'timestamp_defaultnow timestamp(0) without time zone DEFAULT now() NOT NULL '
38
+ );
39
+ };
40
+
41
+ $ this ->verify ($ migrateTemplates , $ generateMigrations , $ beforeVerify );
26
42
}
27
43
28
44
public function testCollation ()
@@ -38,7 +54,7 @@ public function testCollation()
38
54
$ this ->verify ($ migrateTemplates , $ generateMigrations );
39
55
}
40
56
41
- public function verify (callable $ migrateTemplates , callable $ generateMigrations )
57
+ public function verify (callable $ migrateTemplates , callable $ generateMigrations, callable $ beforeVerify = null )
42
58
{
43
59
$ migrateTemplates ();
44
60
@@ -64,9 +80,25 @@ public function verify(callable $migrateTemplates, callable $generateMigrations)
64
80
$ this ->truncateMigration ();
65
81
$ this ->dumpSchemaAs ($ this ->storageSql ('actual.sql ' ));
66
82
83
+ $ beforeVerify === null ?: $ beforeVerify ();
84
+
67
85
$ this ->assertFileEqualsIgnoringOrder (
68
86
$ this ->storageSql ('expected.sql ' ),
69
87
$ this ->storageSql ('actual.sql ' )
70
88
);
71
89
}
90
+
91
+ private function assertLineExistsThenReplace (string $ file , string $ line )
92
+ {
93
+ $ this ->assertTrue (str_contains (
94
+ file_get_contents ($ file ),
95
+ $ line
96
+ ));
97
+
98
+ File::put ($ file , str_replace (
99
+ $ line ,
100
+ 'replaced ' ,
101
+ file_get_contents ($ file )
102
+ ));
103
+ }
72
104
}
0 commit comments