@@ -36,7 +36,7 @@ public function test_return_when_table_string_empty()
36
36
37
37
public function test_generate_single_table_backup ()
38
38
{
39
- $ dateTime = Carbon::parse (" 2024-01-01 12:12:08 " );
39
+ $ dateTime = Carbon::parse (' 2024-01-01 12:12:08 ' );
40
40
Carbon::setTestNow ($ dateTime );
41
41
42
42
$ tableName = 'fathers ' ;
@@ -56,10 +56,9 @@ public function test_generate_single_table_backup()
56
56
Carbon::setTestNow ();
57
57
}
58
58
59
-
60
59
public function test_generate_single_table_backup_with_different_data ()
61
60
{
62
- $ dateTime = Carbon::parse (" 2024-01-07 12:12:08 " );
61
+ $ dateTime = Carbon::parse (' 2024-01-07 12:12:08 ' );
63
62
Carbon::setTestNow ($ dateTime );
64
63
65
64
$ tableName = 'mothers ' ;
@@ -68,14 +67,13 @@ public function test_generate_single_table_backup_with_different_data()
68
67
'types ' => 'one ' ,
69
68
'uuid ' => Str::uuid (),
70
69
'ulid ' => '01J5Y93TVJRVFCSRQFHHF2NRC4 ' ,
71
- 'description ' => "{ar: 'some description'} "
70
+ 'description ' => "{ar: 'some description'} " ,
72
71
]);
73
72
74
73
BackupTables::generateBackup ($ tableName );
75
74
76
75
$ newTableName = $ tableName .'_backup_ ' .now ()->format ('Y_m_d_H_i_s ' );
77
76
78
-
79
77
$ this ->assertTrue (Schema::hasTable ($ newTableName ));
80
78
81
79
$ this ->assertEquals (DB ::table ($ tableName )->value ('types ' ), DB ::table ($ newTableName )->value ('types ' ));
@@ -88,7 +86,7 @@ public function test_generate_single_table_backup_with_different_data()
88
86
89
87
public function test_generate_single_table_backup_then_another_table_backup_later ()
90
88
{
91
- $ dateTime = Carbon::parse (" 2024-01-02 12:12:08 " );
89
+ $ dateTime = Carbon::parse (' 2024-01-02 12:12:08 ' );
92
90
Carbon::setTestNow ($ dateTime );
93
91
94
92
$ fatherTable = 'fathers ' ;
@@ -107,8 +105,8 @@ public function test_generate_single_table_backup_then_another_table_backup_late
107
105
BackupTables::generateBackup ($ fatherTable );
108
106
109
107
$ currentDateTime = now ()->format ('Y_m_d_H_i_s ' );
110
- $ newFatherTable = $ fatherTable . '_backup_ ' . $ currentDateTime ;
111
- $ newSonTable = $ sonTable . '_backup_ ' . $ currentDateTime ;
108
+ $ newFatherTable = $ fatherTable. '_backup_ ' . $ currentDateTime ;
109
+ $ newSonTable = $ sonTable. '_backup_ ' . $ currentDateTime ;
112
110
113
111
$ this ->assertTrue (Schema::hasTable ($ newFatherTable ));
114
112
@@ -124,7 +122,7 @@ public function test_generate_single_table_backup_then_another_table_backup_late
124
122
125
123
public function test_generate_multiple_table_backup ()
126
124
{
127
- $ dateTime = Carbon::parse (" 2024-01-03 12:12:08 " );
125
+ $ dateTime = Carbon::parse (' 2024-01-03 12:12:08 ' );
128
126
Carbon::setTestNow ($ dateTime );
129
127
130
128
$ tableName = 'fathers ' ;
@@ -138,7 +136,7 @@ public function test_generate_multiple_table_backup()
138
136
]);
139
137
140
138
Son::create ([
141
- 'father_id ' => Father::value ('id ' )
139
+ 'father_id ' => Father::value ('id ' ),
142
140
]);
143
141
144
142
BackupTables::generateBackup ([$ tableName , $ tableName2 ]);
@@ -163,7 +161,7 @@ public function test_generate_multiple_table_backup()
163
161
164
162
public function test_generate_single_table_backup_with_with_custom_format ()
165
163
{
166
- $ dateTime = Carbon::parse (" 2024-01-01 12:12:08 " );
164
+ $ dateTime = Carbon::parse (' 2024-01-01 12:12:08 ' );
167
165
Carbon::setTestNow ($ dateTime );
168
166
169
167
$ tableName = 'fathers ' ;
@@ -179,7 +177,7 @@ public function test_generate_single_table_backup_with_with_custom_format()
179
177
180
178
public function test_generate_multiple_models_backup ()
181
179
{
182
- $ dateTime = Carbon::parse (" 2024-01-04 12:12:08 " );
180
+ $ dateTime = Carbon::parse (' 2024-01-04 12:12:08 ' );
183
181
Carbon::setTestNow ($ dateTime );
184
182
$ tableName = Father::class;
185
183
$ tableName2 = Son::class;
@@ -192,24 +190,24 @@ public function test_generate_multiple_models_backup()
192
190
]);
193
191
194
192
Son::create ([
195
- 'father_id ' => Father::value ('id ' )
193
+ 'father_id ' => Father::value ('id ' ),
196
194
]);
197
195
198
196
BackupTables::generateBackup ([$ tableName , $ tableName2 ]);
199
197
200
198
$ tableName = BackupTables::convertModelToTableName ($ tableName );
201
199
$ tableName2 = BackupTables::convertModelToTableName ($ tableName2 );
202
200
203
- $ newTableName = $ tableName . '_backup_ ' . now ()->format ('Y_m_d_H_i_s ' );
204
- $ newTableName2 = $ tableName2 . '_backup_ ' . now ()->format ('Y_m_d_H_i_s ' );
201
+ $ newTableName = $ tableName. '_backup_ ' . now ()->format ('Y_m_d_H_i_s ' );
202
+ $ newTableName2 = $ tableName2. '_backup_ ' . now ()->format ('Y_m_d_H_i_s ' );
205
203
206
204
$ this ->assertTrue (Schema::hasTable ($ newTableName ));
207
205
$ this ->assertTrue (Schema::hasTable ($ newTableName2 ));
208
206
209
207
$ this ->assertEquals (DB ::table ($ tableName )->value ('first_name ' ), DB ::table ($ newTableName )->value ('first_name ' ));
210
208
$ this ->assertEquals (DB ::table ($ tableName )->value ('email ' ), DB ::table ($ newTableName )->value ('email ' ));
211
209
212
- if (DB ::getDriverName () == 'mysql ' || DB ::getDriverName () == 'mariadb ' || (float )App::version () >= Constants::VERSION_AFTER_STORED_AS_VIRTUAL_AS_SUPPORT ) {
210
+ if (DB ::getDriverName () == 'mysql ' || DB ::getDriverName () == 'mariadb ' || (float ) App::version () >= Constants::VERSION_AFTER_STORED_AS_VIRTUAL_AS_SUPPORT ) {
213
211
$ this ->assertEquals (DB ::table ($ tableName )->value ('full_name ' ), DB ::table ($ newTableName )->value ('full_name ' )); // StoredAs/VirtualAs column
214
212
}
215
213
@@ -218,14 +216,14 @@ public function test_generate_multiple_models_backup()
218
216
219
217
public function test_skip_duplicated_backups ()
220
218
{
221
- $ dateTime = Carbon::parse (" 2024-01-05 12:12:08 " );
219
+ $ dateTime = Carbon::parse (' 2024-01-05 12:12:08 ' );
222
220
Carbon::setTestNow ($ dateTime );
223
221
224
222
$ tableName = 'fathers ' ;
225
223
BackupTables::generateBackup ($ tableName );
226
224
BackupTables::generateBackup ($ tableName ); // another backup up will be skipped
227
225
228
- $ newTableName = $ tableName . '_backup_ ' . now ()->format ('Y_m_d_H_i_s ' );
226
+ $ newTableName = $ tableName. '_backup_ ' . now ()->format ('Y_m_d_H_i_s ' );
229
227
230
228
$ this ->assertTrue (Schema::hasTable ($ newTableName ));
231
229
@@ -236,16 +234,16 @@ public function test_skip_duplicated_backups()
236
234
switch ($ databaseDriver ) {
237
235
case 'mysql ' :
238
236
case 'mariadb ' :
239
- $ result = DB ::select (/**@lang MySQL*/ "
237
+ $ result = DB ::select (/**@lang MySQL*/ '
240
238
SELECT COUNT(*) as count
241
239
FROM information_schema.tables
242
240
WHERE table_schema = DATABASE()
243
- AND table_name LIKE ? " , [$ pattern ]);
241
+ AND table_name LIKE ? ' , [$ pattern ]);
244
242
$ count = $ result [0 ]->count ;
245
243
break ;
246
244
247
245
case 'pgsql ' :
248
- $ result = DB ::select (/**@lang PostgreSQL*/ "
246
+ $ result = DB ::select (/**@lang PostgreSQL*/ "
249
247
SELECT COUNT(*) as count
250
248
FROM information_schema.tables
251
249
WHERE table_schema = 'public'
@@ -261,17 +259,15 @@ public function test_skip_duplicated_backups()
261
259
break ;
262
260
263
261
case 'sqlsrv ' :
264
- $ result = DB ::select (/**@lang TSQL*/ "
262
+ $ result = DB ::select (/**@lang TSQL*/ '
265
263
SELECT COUNT(*) as count
266
264
FROM sys.tables
267
- WHERE name LIKE ? " , [$ pattern ]);
265
+ WHERE name LIKE ? ' , [$ pattern ]);
268
266
$ count = $ result [0 ]->count ;
269
267
break ;
270
268
}
271
269
$ this ->assertEquals (1 , $ count );
272
270
273
-
274
271
Carbon::setTestNow ();
275
272
}
276
-
277
273
}
0 commit comments