@@ -81,7 +81,7 @@ public function testCSVExportBasic()
8181 $ exportDevice = new Local ($ tempDir );
8282
8383 // Create CSV destination
84- $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' );
84+ $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , '' , ' test_db_test_table_id ' );
8585
8686 // Create test data
8787 $ database = new Database ('test_db ' );
@@ -112,7 +112,6 @@ public function testCSVExportBasic()
112112 $ csvDestination ->shutdown ();
113113
114114 // Verify CSV file was created in local temp directory
115- // Note: The filename gets sanitized, so ':' becomes '_'
116115 $ expectedFile = $ csvDestination ->getLocalRoot () . '/test_db_test_table_id.csv ' ;
117116 $ this ->assertFileExists ($ expectedFile , 'CSV file should exist ' );
118117
@@ -132,16 +131,19 @@ public function testCSVExportBasic()
132131 // Check header
133132 $ this ->assertContains ('$id ' , $ header );
134133 $ this ->assertContains ('$permissions ' , $ header );
134+ $ this ->assertContains ('$createdAt ' , $ header );
135+ $ this ->assertContains ('$updatedAt ' , $ header );
135136 $ this ->assertContains ('name ' , $ header );
136137 $ this ->assertContains ('age ' , $ header );
137138 $ this ->assertContains ('email ' , $ header );
138139
139140 // Check first row data
140141 $ this ->assertEquals ('row1 ' , $ row1Data [0 ]); // $id
141142 $ this ->assertStringContainsString ('user:123 ' , $ row1Data [1 ]); // $permissions
142- $ this ->assertEquals ('John Doe ' , $ row1Data [2 ]); // name
143- $ this ->assertEquals ('30 ' , $ row1Data [3 ]); // age
144- $ this ->assertEquals ('john@example.com ' , $ row1Data [4 ]); // email
143+ // $createdAt and $updatedAt are empty for test data
144+ $ this ->assertEquals ('John Doe ' , $ row1Data [4 ]); // name
145+ $ this ->assertEquals ('30 ' , $ row1Data [5 ]); // age
146+ $ this ->assertEquals ('john@example.com ' , $ row1Data [6 ]); // email
145147
146148 // Cleanup
147149 if (is_dir ($ tempDir )) {
@@ -154,7 +156,7 @@ public function testCSVExportWithSpecialCharacters()
154156 $ tempDir = sys_get_temp_dir () . '/csv_test_special_ ' . uniqid ();
155157 $ exportDevice = new Local ($ tempDir );
156158
157- $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' );
159+ $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , '' , ' test_db_test_table_id ' );
158160
159161 $ database = new Database ('test_db ' );
160162 $ table = new Table ($ database , 'test_table ' , 'test_table_id ' );
@@ -183,11 +185,12 @@ public function testCSVExportWithSpecialCharacters()
183185 $ this ->assertNotFalse ($ header );
184186 $ this ->assertNotFalse ($ rowData );
185187
186- // Verify special characters are properly handled (fgetcsv($handle, 0, ',', '"', '"');
187- $ this ->assertEquals ('Text with "quotes" ' , $ rowData [2 ]); // quote_field
188- $ this ->assertEquals ('Text, with, commas ' , $ rowData [3 ]); // comma_field
189- $ this ->assertEquals ("Text with \nnewlines " , $ rowData [4 ]); // newline_field
190- $ this ->assertEquals ('Text with "quotes", commas, and\nnewlines ' , $ rowData [5 ]); // mixed_field
188+ // Verify special characters are properly handled
189+ // Indices are shifted by 2 due to $createdAt and $updatedAt
190+ $ this ->assertEquals ('Text with "quotes" ' , $ rowData [4 ]); // quote_field
191+ $ this ->assertEquals ('Text, with, commas ' , $ rowData [5 ]); // comma_field
192+ $ this ->assertEquals ("Text with \nnewlines " , $ rowData [6 ]); // newline_field
193+ $ this ->assertEquals ('Text with "quotes", commas, and\nnewlines ' , $ rowData [7 ]); // mixed_field
191194
192195 // Cleanup
193196 if (is_dir ($ tempDir )) {
@@ -200,7 +203,7 @@ public function testCSVExportWithArrays()
200203 $ tempDir = sys_get_temp_dir () . '/csv_test_arrays_ ' . uniqid ();
201204 $ exportDevice = new Local ($ tempDir );
202205
203- $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' );
206+ $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , '' , ' test_db_test_table_id ' );
204207
205208 $ database = new Database ('test_db ' );
206209 $ table = new Table ($ database , 'test_table ' , 'test_table_id ' );
@@ -229,10 +232,11 @@ public function testCSVExportWithArrays()
229232 $ this ->assertNotFalse ($ rowData );
230233
231234 // Arrays should be JSON encoded
232- $ this ->assertEquals ('["php","csv","export"] ' , $ rowData [2 ]); // tags
233- $ this ->assertJson ($ rowData [3 ]); // metadata should be valid JSON
234- $ this ->assertEquals ('' , $ rowData [4 ]); // empty_array
235- $ this ->assertJson ($ rowData [5 ]); // nested should be valid JSON
235+ // Indices are shifted by 2 due to $createdAt and $updatedAt
236+ $ this ->assertEquals ('["php","csv","export"] ' , $ rowData [4 ]); // tags
237+ $ this ->assertJson ($ rowData [5 ]); // metadata should be valid JSON
238+ $ this ->assertEquals ('' , $ rowData [6 ]); // empty_array
239+ $ this ->assertJson ($ rowData [7 ]); // nested should be valid JSON
236240
237241 // Cleanup
238242 if (is_dir ($ tempDir )) {
@@ -245,7 +249,7 @@ public function testCSVExportWithNullValues()
245249 $ tempDir = sys_get_temp_dir () . '/csv_test_nulls_ ' . uniqid ();
246250 $ exportDevice = new Local ($ tempDir );
247251
248- $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' );
252+ $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , '' , ' test_db_test_table_id ' );
249253
250254 $ database = new Database ('test_db ' );
251255 $ table = new Table ($ database , 'test_table ' , 'test_table_id ' );
@@ -274,11 +278,12 @@ public function testCSVExportWithNullValues()
274278 $ this ->assertNotFalse ($ header );
275279 $ this ->assertNotFalse ($ rowData );
276280
277- $ this ->assertEquals ('Test ' , $ rowData [2 ]); // name
278- $ this ->assertEquals ('null ' , $ rowData [3 ]); // null_field -> "null" string
279- $ this ->assertEquals ('' , $ rowData [4 ]); // empty_string
280- $ this ->assertEquals ('0 ' , $ rowData [5 ]); // zero
281- $ this ->assertEquals ('false ' , $ rowData [6 ]); // false_bool
281+ // Indices are shifted by 2 due to $createdAt and $updatedAt
282+ $ this ->assertEquals ('Test ' , $ rowData [4 ]); // name
283+ $ this ->assertEquals ('null ' , $ rowData [5 ]); // null_field -> "null" string
284+ $ this ->assertEquals ('' , $ rowData [6 ]); // empty_string
285+ $ this ->assertEquals ('0 ' , $ rowData [7 ]); // zero
286+ $ this ->assertEquals ('false ' , $ rowData [8 ]); // false_bool
282287
283288 // Cleanup
284289 if (is_dir ($ tempDir )) {
@@ -292,7 +297,7 @@ public function testCSVExportWithAllowedAttributes()
292297 $ exportDevice = new Local ($ tempDir );
293298
294299 // Only allow specific attributes
295- $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , ['name ' , 'email ' ]);
300+ $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , '' , ' test_db_test_table_id ' , ['name ' , 'email ' ]);
296301
297302 $ database = new Database ('test_db ' );
298303 $ table = new Table ($ database , 'test_table ' , 'test_table_id ' );
@@ -320,9 +325,11 @@ public function testCSVExportWithAllowedAttributes()
320325 $ this ->assertNotFalse ($ header );
321326 $ this ->assertNotFalse ($ rowData );
322327
323- // Should have $id, $permissions, and only allowed attributes
328+ // Should have $id, $permissions, $createdAt, $updatedAt, and only allowed attributes
324329 $ this ->assertContains ('$id ' , $ header );
325330 $ this ->assertContains ('$permissions ' , $ header );
331+ $ this ->assertContains ('$createdAt ' , $ header );
332+ $ this ->assertContains ('$updatedAt ' , $ header );
326333 $ this ->assertContains ('name ' , $ header );
327334 $ this ->assertContains ('email ' , $ header );
328335 $ this ->assertNotContains ('age ' , $ header );
@@ -340,7 +347,7 @@ public function testCSVExportImportCompatibility()
340347 $ exportDevice = new Local ($ tempDir );
341348
342349 // Export data
343- $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' );
350+ $ csvDestination = new TestCSV ($ exportDevice , 'test_db:test_table_id ' , '' , ' test_db_test_table_id ' );
344351
345352 $ database = new Database ('test_db ' );
346353 $ table = new Table ($ database , 'test_table ' , 'test_table_id ' );
@@ -384,6 +391,9 @@ public function testCSVExportImportCompatibility()
384391 $ this ->assertEquals ('null ' , $ reconstructed ['null_field ' ]); // null becomes "null" string
385392 $ this ->assertEquals ('' , $ reconstructed ['empty_field ' ]);
386393 $ this ->assertEquals ('true ' , $ reconstructed ['bool_field ' ]); // bool becomes string
394+ // Check that createdAt and updatedAt are in the reconstructed data
395+ $ this ->assertArrayHasKey ('$createdAt ' , $ reconstructed );
396+ $ this ->assertArrayHasKey ('$updatedAt ' , $ reconstructed );
387397
388398 // Arrays should be valid JSON that can be decoded
389399 $ this ->assertJson ($ reconstructed ['tags ' ]);
0 commit comments