-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathFileReadCommandTest.php
More file actions
356 lines (290 loc) · 15.9 KB
/
FileReadCommandTest.php
File metadata and controls
356 lines (290 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
declare(strict_types=1);
namespace Flow\CLI\Tests\Integration;
use Flow\CLI\Command\{FileReadCommand};
use Flow\ETL\Tests\CommandOutputNormalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
final class FileReadCommandTest extends TestCase
{
use CommandOutputNormalizer;
public function test_read_rows_csv() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.csv', '--input-file-limit' => 5]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+----------------------+----------------------+----------------------+----------+----------------------+----------------------+----------------------+
| order_id | created_at | updated_at | discount | address | notes | items |
+----------------------+----------------------+----------------------+----------+----------------------+----------------------+----------------------+
| e13d7098-5a78-3389-9 | 2024-06-17T19:24:49+ | 2024-06-17T19:24:49+ | 12.45 | {"street":"9742 Jask | ["Doloremque cum et | [{"sku":"SKU_0003"," |
| 947df050-3abb-3f5a-9 | 2024-02-23T19:18:53+ | 2024-02-23T19:18:53+ | | {"street":"37051 Ale | ["Neque dolor et min | [{"sku":"SKU_0004"," |
| 6315f9e2-86bf-3321-a | 2024-04-02T11:30:25+ | 2024-04-02T11:30:25+ | 47.1 | {"street":"792 Golda | ["Et porro fugiat fu | [{"sku":"SKU_0003"," |
| 4cccb632-fade-34e2-8 | 2024-05-06T00:17:57+ | 2024-05-06T00:17:57+ | 19.76 | {"street":"30203 Wal | ["Aliquam saepe iste | [{"sku":"SKU_0004"," |
| 82384f8c-9adb-38be-9 | 2024-05-10T11:17:41+ | 2024-05-10T11:17:41+ | | {"street":"757 Tobin | ["Beatae nesciunt au | [{"sku":"SKU_0005"," |
+----------------------+----------------------+----------------------+----------+----------------------+----------------------+----------------------+
5 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_excel() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.xlsx', '--input-file-limit' => 5]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+----------------------+----------------------+----------------------+----------+----------------------+----------------------+----------------------+
| order_id | created_at | updated_at | discount | address | notes | items |
+----------------------+----------------------+----------------------+----------+----------------------+----------------------+----------------------+
| e13d7098-5a78-3389-9 | 2024-06-17T19:24:49+ | 2024-06-17T19:24:49+ | 12.45 | {"street":"9742 Jask | ["Doloremque cum et | [{"sku":"SKU_0003"," |
| 947df050-3abb-3f5a-9 | 2024-02-23T19:18:53+ | 2024-02-23T19:18:53+ | | {"street":"37051 Ale | ["Neque dolor et min | [{"sku":"SKU_0004"," |
| 6315f9e2-86bf-3321-a | 2024-04-02T11:30:25+ | 2024-04-02T11:30:25+ | 47.1 | {"street":"792 Golda | ["Et porro fugiat fu | [{"sku":"SKU_0003"," |
| 4cccb632-fade-34e2-8 | 2024-05-06T00:17:57+ | 2024-05-06T00:17:57+ | 19.76 | {"street":"30203 Wal | ["Aliquam saepe iste | [{"sku":"SKU_0004"," |
| 82384f8c-9adb-38be-9 | 2024-05-10T11:17:41+ | 2024-05-10T11:17:41+ | | {"street":"757 Tobin | ["Beatae nesciunt au | [{"sku":"SKU_0005"," |
+----------------------+----------------------+----------------------+----------+----------------------+----------------------+----------------------+
5 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_json() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.json', '--input-file-limit' => 5]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputIdentical(
<<<'OUTPUT'
+----------------------+----------------------+----------------------+--------------+-------------+-----------+----------------------+----------------------+----------------------+
| order_id | created_at | updated_at | cancelled_at | total_price | discount | customer | address | notes |
+----------------------+----------------------+----------------------+--------------+-------------+-----------+----------------------+----------------------+----------------------+
| e5e0299f-152e-4c1b-b | 2023-10-02T23:59:16+ | 2023-10-10T11:43:41+ | | 170.050000 | 32.090000 | {"name":"Adah","last | {"street":"73121 Swi | ["Sit dolor quas aut |
| 139aa6b6-872b-47a8-b | 2023-05-20T08:59:30+ | 2023-10-12T03:24:25+ | | 239.940000 | 47.790000 | {"name":"Kasandra"," | {"street":"5864 Kael | ["Architecto quod cu |
| 35d90c5c-c524-4b24-a | 2023-05-13T13:56:02+ | 2023-09-28T10:27:33+ | | 148.380000 | 3.080000 | {"name":"Shaina","la | {"street":"651 Okune | ["Sit voluptates sin |
| e84a65ff-4438-4275-8 | 2023-10-03T00:27:46+ | 2023-10-10T07:59:28+ | | 384.490000 | 7.880000 | {"name":"Dane","last | {"street":"7465 Spor | ["Id illo autem eaqu |
| 86f3d0ca-a047-4866-9 | 2023-08-06T21:54:08+ | 2023-10-05T13:15:17+ | | 265.440000 | 32.370000 | {"name":"Mireille"," | {"street":"671 Korbi | ["Dolorem accusantiu |
+----------------------+----------------------+----------------------+--------------+-------------+-----------+----------------------+----------------------+----------------------+
5 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_parquet() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.parquet', '--input-file-limit' => 5]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputIdentical(
<<<'OUTPUT'
+----------------------+----------------------+----------------------+-----------+----------------------+------------------+----------------------+----------------------+----------------------+
| order_id | created_at | updated_at | discount | email | customer | address | notes | items |
+----------------------+----------------------+----------------------+-----------+----------------------+------------------+----------------------+----------------------+----------------------+
| 4e93f175-0c89-30df-a | 2026-01-29T13:48:47+ | 2026-02-15T13:48:47+ | 27.969999 | fahey.aurelie@denesi | Jerod Abbott | {"street":"5567 Grim | ["Maxime et sed impe | [{"sku":"SKU_0004"," |
| db560d65-3a26-359e-8 | 2026-02-15T18:39:41+ | | 35.990002 | dusty70@howell.com | Omari McGlynn | {"street":"86184 Mck | ["Mollitia eos optio | [{"sku":"SKU_0001"," |
| f24d7f7d-1615-3b5b-a | 2026-01-26T05:23:13+ | 2026-02-01T05:23:13+ | 42.669998 | linnea91@gmail.com | Kendall Weissnat | {"street":"65268 Apr | ["Ut nesciunt volupt | [{"sku":"SKU_0003"," |
| 78fe7069-f06f-3081-b | 2026-03-12T13:08:56+ | | | glubowitz@morissette | Roman Balistreri | {"street":"1722 Hall | ["Velit vero invento | [{"sku":"SKU_0005"," |
| e3fb781c-34ff-380f-8 | 2026-01-10T18:34:34+ | 2026-02-06T18:34:34+ | | walton60@hand.com | Sedrick Ondricka | {"street":"201 Mosci | ["Doloremque culpa i | [{"sku":"SKU_0004"," |
+----------------------+----------------------+----------------------+-----------+----------------------+------------------+----------------------+----------------------+----------------------+
5 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_text() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.txt', '--input-file-limit' => 5]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+----------------------+
| text |
+----------------------+
| order_id,created_at, |
| e13d7098-5a78-3389-9 |
| 947df050-3abb-3f5a-9 |
| 6315f9e2-86bf-3321-a |
| 4cccb632-fade-34e2-8 |
+----------------------+
5 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_with_large_offset() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-offset' => 1000,
]);
$tester->assertCommandIsSuccessful();
$output = $tester->getDisplay();
// Should show empty output as offset is larger than file
self::assertEmpty(trim($output));
}
public function test_read_rows_with_offset_and_columns() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 4,
'--input-file-offset' => 1,
'--output-columns' => ['order_id', 'discount'],
]);
$tester->assertCommandIsSuccessful();
$output = $tester->getDisplay();
// Should skip first row and show next 3 rows with only order_id and discount columns
self::assertStringNotContainsString('e13d7098-5a78-3389-9', $output); // First row should not be displayed
self::assertCommandOutputContains('947df050-3abb-3f5a-9', $output); // Second row should be first displayed
self::assertCommandOutputContains('6315f9e2-86bf-3321-a', $output); // Third row should be displayed
self::assertCommandOutputContains('4cccb632-fade-34e2-8', $output); // Fourth row should be displayed
self::assertCommandOutputContains('3 rows', $output); // Should show 3 rows
// Should only show selected columns
self::assertCommandOutputContains('order_id', $output);
self::assertCommandOutputContains('discount', $output);
self::assertStringNotContainsString('created_at', $output);
self::assertStringNotContainsString('address', $output);
}
public function test_read_rows_with_offset_csv() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 3,
'--input-file-offset' => 2,
]);
$tester->assertCommandIsSuccessful();
$output = $tester->getDisplay();
// Should display rows starting from offset 2 (third row)
self::assertCommandOutputContains('6315f9e2-86bf-3321-a', $output); // Third row should be first displayed
self::assertStringNotContainsString('e13d7098-5a78-3389-9', $output); // First row should not be displayed
self::assertStringNotContainsString('947df050-3abb-3f5a-9', $output); // Second row should not be displayed
self::assertCommandOutputContains('1 rows', $output); // Only 1 row should be displayed (limit 3 - offset 2)
}
public function test_read_rows_with_offset_zero() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 2,
'--input-file-offset' => 0,
]);
$tester->assertCommandIsSuccessful();
$output = $tester->getDisplay();
// Should behave same as no offset - show first 2 rows
self::assertCommandOutputContains('e13d7098-5a78-3389-9', $output); // First row should be displayed
self::assertCommandOutputContains('947df050-3abb-3f5a-9', $output); // Second row should be displayed
self::assertCommandOutputContains('2 rows', $output);
}
public function test_read_rows_with_output_columns_empty_maintains_all_columns() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 2,
]);
$tester->assertCommandIsSuccessful();
// Should contain all original columns (order_id, created_at, updated_at, discount, address, notes, items)
$output = $tester->getDisplay();
self::assertCommandOutputContains('order_id', $output);
self::assertCommandOutputContains('created_at', $output);
self::assertCommandOutputContains('updated_at', $output);
self::assertCommandOutputContains('discount', $output);
self::assertCommandOutputContains('address', $output);
self::assertCommandOutputContains('notes', $output);
self::assertCommandOutputContains('items', $output);
self::assertCommandOutputContains('2 rows', $output);
}
public function test_read_rows_with_output_columns_multiple_columns() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 3,
'--output-columns' => ['order_id', 'discount', 'created_at'],
]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+----------------------+----------+----------------------+
| order_id | discount | created_at |
+----------------------+----------+----------------------+
| e13d7098-5a78-3389-9 | 12.45 | 2024-06-17T19:24:49+ |
| 947df050-3abb-3f5a-9 | | 2024-02-23T19:18:53+ |
| 6315f9e2-86bf-3321-a | 47.1 | 2024-04-02T11:30:25+ |
+----------------------+----------+----------------------+
3 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_with_output_columns_nonexistent_column() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 2,
'--output-columns' => ['nonexistent_column'],
]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+--------------------+
| nonexistent_column |
+--------------------+
| |
| |
+--------------------+
2 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_with_output_columns_single_column() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute([
'input-file' => __DIR__ . '/Fixtures/orders.csv',
'--input-file-limit' => 3,
'--output-columns' => ['order_id'],
]);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+----------------------+
| order_id |
+----------------------+
| e13d7098-5a78-3389-9 |
| 947df050-3abb-3f5a-9 |
| 6315f9e2-86bf-3321-a |
+----------------------+
3 rows
OUTPUT,
$tester->getDisplay()
);
}
public function test_read_rows_xml() : void
{
$tester = new CommandTester(new FileReadCommand('read'));
$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.xml', '--input-file-limit' => 5, '--input-xml-node-path' => 'root/row']);
$tester->assertCommandIsSuccessful();
self::assertCommandOutputContains(
<<<'OUTPUT'
+----------------------+
| node |
+----------------------+
| <row> <order_id/ |
| <row> <order_id/ |
| <row> <order_id/ |
| <row> <order_id/ |
| <row> <order_id/ |
+----------------------+
5 rows
OUTPUT,
$tester->getDisplay()
);
}
}