-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
MigrateRunnerTest.php
548 lines (480 loc) · 25.5 KB
/
MigrateRunnerTest.php
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<?php
namespace Unish;
use Drupal\migrate\Plugin\MigrationInterface;
use Webmozart\PathUtil\Path;
/**
* @group commands
* @coversDefaultClass \Drush\Drupal\Commands\core\MigrateRunnerCommands
*/
class MigrateRunnerTest extends UnishIntegrationTestCase
{
use TestModuleHelperTrait;
/**
* {@inheritdoc}
*/
protected function setUp(): void
{
parent::setUp();
$this->setupModulesForTests(['woot'], Path::join(__DIR__, '/../fixtures/modules'));
$this->drush('pm:install', ['migrate', 'node', 'woot']);
}
/**
* @covers ::status
* @covers ::getMigrationList
*/
public function testMigrateStatus(): void
{
// No arguments, no options.
$this->drush('migrate:status', [], [
'format' => 'json',
'debug' => null,
]);
$output = $this->getOutputFromJSON();
$actualIds = array_column($output, 'id');
$this->assertCount(3, $actualIds);
$this->assertContains('test_migration', $actualIds);
$this->assertContains('test_migration_tagged', $actualIds);
$this->assertContains('test_migration_untagged', $actualIds);
// Debug message registered for 'test_migration_source_issues'.
// @see \Drush\Drupal\Commands\core\MigrateRunnerCommands::getMigrationList()
$this->assertStringContainsString("[debug] Migration 'test_migration_source_issues' is skipped as its source plugin has missed requirements: type1: a. type1: b. type1: c. type2: x. type2: y. type2: z.", $this->getErrorOutputRaw());
// With arguments.
$this->drush(
'migrate:status',
['test_migration_tagged,test_migration_untagged'],
['format' => 'json']
);
$output = $this->getOutputFromJSON();
$actualIds = array_column($output, 'id');
$this->assertCount(2, $actualIds);
$this->assertContains('test_migration_tagged', $actualIds);
$this->assertContains('test_migration_untagged', $actualIds);
// Using --tag with value.
$this->drush('migrate:status', [], ['tag' => 'tag1,tag2', 'format' => 'json']);
$output = $this->getOutputFromJSON();
$this->assertCount(7, $output);
// Tag: tag1. The first line contains the tag.
$this->assertEquals('Tag: tag1', $output[0]['id']);
// When using --tag, the migration IDs are indented, so we trim().
$this->assertEquals('test_migration', trim($output[1]['id']));
$this->assertEquals('test_migration_tagged', trim($output[2]['id']));
// There's an empty row after each tag group.
$this->assertNull($output[3]['id']);
// Tag: tag2
$this->assertEquals('Tag: tag2', $output[4]['id']);
$this->assertEquals('test_migration_tagged', trim($output[5]['id']));
$this->assertNull($output[6]['id']);
// Check that --names-only takes precedence over --fields.
$this->drush('migrate:status', [], [
'names-only' => null,
'fields' => 'id,status,imported',
'format' => 'json',
]);
$output = $this->getOutputFromJSON();
$this->assertArrayHasKey('id', $output[0]);
$this->assertArrayNotHasKey('status', $output[0]);
$this->assertArrayNotHasKey('total', $output[0]);
$this->assertArrayNotHasKey('imported', $output[0]);
$this->assertArrayNotHasKey('needing_update', $output[0]);
$this->assertArrayNotHasKey('unprocessed', $output[0]);
$this->assertArrayNotHasKey('last_imported', $output[0]);
// Check that the deprecation warning is printed.
$this->assertStringContainsString('The --names-only option is deprecated in Drush 10.5.1 and is removed from Drush 11.0.0. Use --field=id instead.', $this->getErrorOutput());
// Check improper usage of --names-only with --field.
$this->drush('migrate:status', [], [
'field' => 'status',
'names-only' => null,
], self::EXIT_ERROR);
$this->assertStringContainsString('Cannot use --names-only with --field=status.', $this->getErrorOutput());
$actualIds = array_column($output, 'id');
$this->assertCount(3, $actualIds);
$this->assertContains('test_migration', $actualIds);
$this->assertContains('test_migration_tagged', $actualIds);
$this->assertContains('test_migration_untagged', $actualIds);
// Check that invalid migration IDs are reported.
$this->drush('migrate:status', ['non_existing,test_migration,another_invalid'], [], self::EXIT_ERROR);
$this->assertStringContainsString('Invalid migration IDs: non_existing, another_invalid', $this->getErrorOutput());
// Check --fields option.
$this->drush('migrate:status', [], [
'fields' => 'id,status,needing_update',
'format' => 'json',
]);
$this->assertArrayHasKey('id', $this->getOutputFromJSON(0));
$this->assertArrayHasKey('status', $this->getOutputFromJSON(0));
$this->assertArrayHasKey('needing_update', $this->getOutputFromJSON(0));
$this->assertArrayNotHasKey('total', $this->getOutputFromJSON(0));
$this->assertArrayNotHasKey('imported', $this->getOutputFromJSON(0));
$this->assertArrayNotHasKey('unprocessed', $this->getOutputFromJSON(0));
$this->assertArrayNotHasKey('last_imported', $this->getOutputFromJSON(0));
$this->assertArrayHasKey('id', $this->getOutputFromJSON(1));
$this->assertArrayHasKey('status', $this->getOutputFromJSON(1));
$this->assertArrayHasKey('needing_update', $this->getOutputFromJSON(1));
$this->assertArrayNotHasKey('total', $this->getOutputFromJSON(1));
$this->assertArrayNotHasKey('imported', $this->getOutputFromJSON(1));
$this->assertArrayNotHasKey('unprocessed', $this->getOutputFromJSON(1));
$this->assertArrayNotHasKey('last_imported', $this->getOutputFromJSON(1));
$this->assertArrayHasKey('id', $this->getOutputFromJSON(2));
$this->assertArrayHasKey('status', $this->getOutputFromJSON(2));
$this->assertArrayHasKey('needing_update', $this->getOutputFromJSON(2));
$this->assertArrayNotHasKey('total', $this->getOutputFromJSON(2));
$this->assertArrayNotHasKey('imported', $this->getOutputFromJSON(2));
$this->assertArrayNotHasKey('unprocessed', $this->getOutputFromJSON(2));
$this->assertArrayNotHasKey('last_imported', $this->getOutputFromJSON(2));
}
/**
* @covers ::import
* @covers ::rollback
*/
public function testMigrateImportAndRollback(): void
{
// Trigger logging in ProcessRowTestSubscriber::onPrepareRow().
// @see \Drupal\woot\EventSubscriber\ProcessRowTestSubscriber::onPrepareRow()
// @see \Drupal\woot\EventSubscriber\PreRowDeleteTestSubscriber::onPreRowDelete()
$this->drush('state:set', ['woot.migrate_runner.trigger_failures', true]);
// Warm-up the 'migrate_prepare_row' hook implementations cache to test
// that system_migrate_prepare_row() is picked-up during import. See
// MigrateEvents::DRUSH_MIGRATE_PREPARE_ROW test, later.
// @see system_migrate_prepare_row()
// @see \Drupal\woot\EventSubscriber\ProcessRowTestSubscriber::onPrepareRow()
$this->drush('php:eval', ["Drupal::moduleHandler()->invokeAll('migrate_prepare_row');"]);
// Expect that this command will fail because the 2nd row fails.
// @see \Drupal\woot\Plugin\migrate\process\TestFailProcess
$this->drush('migrate:import', ['test_migration'], [], self::EXIT_ERROR);
// Check for the expected command output.
$output = $this->getErrorOutput();
$this->assertStringContainsString('Processed 2 items (1 created, 0 updated, 1 failed, 0 ignored)', $output);
$this->assertStringContainsString('test_migration migration: 1 failed.', $output);
// Check if the MigrateEvents::DRUSH_MIGRATE_PREPARE_ROW event is dispatched.
$this->assertStringContainsString('MigrateEvents::DRUSH_MIGRATE_PREPARE_ROW fired for row with ID 1', $output);
$this->assertStringContainsString('MigrateEvents::DRUSH_MIGRATE_PREPARE_ROW fired for row with ID 2', $output);
// Check that nid 1 has been imported successfully while nid 2 failed.
// @see \Drupal\woot\Plugin\migrate\process\TestFailProcess
$this->drush('sql:query', ['SELECT title FROM node_field_data']);
$this->assertSame(['Item 1'], $this->getOutputAsList());
// Check that an appropriate error is logged when rollback fails.
// @see \Drupal\woot\EventSubscriber\PreRowDeleteTestSubscriber::onPreRowDelete()
$this->drush('migrate:rollback', [], ['all' => null], self::EXIT_ERROR);
$this->assertStringContainsString('Earthquake while rolling back', $this->getErrorOutputRaw());
$this->drush('migrate:reset', ['test_migration']);
// Reset the flag, so we won't fail the rollback again.
$this->drush('state:delete', ['woot.migrate_runner.trigger_failures']);
$this->drush('migrate:rollback', ['test_migration']);
// Note that item with source ID 2, which failed to import, was already
// deleted from the map in the previous rollback.
$this->assertStringContainsString('Rolled back 1 item', $this->getErrorOutput());
// Check that the migration rollback removes both nodes from backend.
$this->drush('sql:query', ['SELECT title FROM node_field_data']);
$this->assertEmpty(array_filter($this->getOutputAsList()));
$this->drush('migrate:status', ['test_migration'], [
'format' => 'json',
]);
// Check that status and last import time were reset.
// @see https://www.drupal.org/project/migrate_tools/issues/3011996
$this->assertSame('Idle', $this->getOutputFromJSON(0)['status']);
$this->assertEmpty($this->getOutputFromJSON(0)['last_imported']);
// Test that dependent migrations run only once.
$this->drush('migrate:import', ['test_migration_tagged,test_migration_untagged'], ['execute-dependencies' => null]);
foreach (['test_migration_tagged', 'test_migration_untagged'] as $migration_id) {
$occurrences = substr_count($this->getErrorOutput(), "done with '$migration_id'");
$this->assertEquals(1, $occurrences);
}
}
/**
* @covers ::import
* @covers ::rollback
*/
public function testMigrateImportAndRollbackWithIdList(): void
{
// Enlarge the source recordset to 50 rows.
$this->drush('state:set', ['woot.migrate_runner.source_data_amount', 50]);
$this->drush('migrate:import', ['test_migration'], [
// Intentionally added 56, which is out of bounds.
'idlist' => '4,12,29,34,56',
]);
$this->drush('migrate:status', ['test_migration'], [
'format' => 'json',
]);
// Check that only rows with ID 4, 12, 29, 34 were imported.
$this->assertSame(50, $this->getOutputFromJSON(0)['total']);
$this->assertSame('4 (8%)', $this->getOutputFromJSON(0)['imported']);
$this->assertSame(46, $this->getOutputFromJSON(0)['unprocessed']);
$this->drush('sql:query', ['SELECT title FROM node_field_data']);
$this->assertSame(['Item 4', 'Item 12', 'Item 29', 'Item 34'], $this->getOutputAsList());
$this->drush('migrate:rollback', ['test_migration'], [
// Intentionally added 56, which is out of bounds.
'idlist' => '4,34,56',
]);
$this->drush('migrate:status', ['test_migration'], ['format' => 'json']);
// Check that only rows with ID 4 and 34 were rolled back.
$this->assertSame(50, $this->getOutputFromJSON(0)['total']);
$this->assertSame('2 (4%)', $this->getOutputFromJSON(0)['imported']);
$this->assertSame(48, $this->getOutputFromJSON(0)['unprocessed']);
$this->drush('sql:query', ['SELECT title FROM node_field_data']);
$this->assertEquals(['Item 12', 'Item 29'], $this->getOutputAsList());
}
/**
* @covers ::import
* @covers \Drush\Drupal\Migrate\MigrateExecutable::handleMissingSourceRows
*/
public function testMissingSourceRows(): void
{
$this->drush('state:set', ['woot.migrate_runner.source_data_amount', 5]);
$this->drush('migrate:import', ['test_migration']);
$this->assertStringContainsString('[notice] Processed 5 items (5 created, 0 updated, 0 failed, 0 ignored)', $this->getErrorOutput());
$this->drush('sql:query', ['SELECT title FROM node_field_data']);
$this->assertSame(['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'], $this->getOutputAsList());
$this->drush('state:set', ['woot.migrate_runner.removed_source_rows', '2,4']);
// Get fresh plugin definitions.
drupal_flush_all_caches();
$this->drush('migrate:import', ['test_migration'], ['delete' => null]);
$this->assertStringContainsString('[notice] 2 items are missing from source and will be rolled back', $this->getErrorOutput());
$this->assertStringContainsString("[notice] Rolled back 2 items - done with 'test_migration'", $this->getErrorOutput());
$this->assertStringContainsString('[notice] Processed 0 items (0 created, 0 updated, 0 failed, 0 ignored)', $this->getErrorOutput());
$this->drush('sql:query', ['SELECT title FROM node_field_data']);
$this->assertSame(['Item 1', 'Item 3', 'Item 5'], $this->getOutputAsList());
}
/**
* @covers ::stop
* @covers ::resetStatus
*/
public function testMigrateStopAndResetStatus(): void
{
$this->drush('migrate:stop', ['test_migration']);
// @todo Find a way to stop a migration that runs.
$this->assertStringContainsString('Migration test_migration is idle', $this->getErrorOutput());
$this->drush('migrate:reset', ['test_migration']);
// @todo Find a way to reset a migration that is not idle.
$this->assertStringContainsString('Migration test_migration is already Idle', $this->getErrorOutput());
}
/**
* @covers ::messages
* @covers ::fieldsSource
*/
public function testMigrateMessagesAndFieldSource(): void
{
$this->drush('state:set', ['woot.migrate_runner.source_data_amount', 20]);
$this->drush('state:set', ['woot.migrate_runner.trigger_failures', true]);
$this->drush('migrate:import', ['test_migration'], [
'no-progress' => null,
], self::EXIT_ERROR);
// All messages together.
$this->drush('migrate:messages', ['test_migration'], ['format' => 'json']);
$output = $this->getOutputFromJSON();
// @see \Drupal\woot\Plugin\migrate\process\TestFailProcess::transform()
$this->assertCount(3, $output);
$this->assertEquals(1, $output[0]['level']);
$this->assertSame('2', $output[0]['source_ids']);
$this->assertEmpty($output[0]['destination_ids']);
$this->assertStringContainsString('ID 2 should fail', $output[0]['message']);
$this->assertEquals(1, $output[1]['level']);
$this->assertSame('9', $output[1]['source_ids']);
$this->assertEmpty($output[0]['destination_ids']);
$this->assertStringContainsString('ID 9 should fail', $output[1]['message']);
$this->assertEquals(1, $output[2]['level']);
$this->assertStringContainsString('ID 17 should fail', $output[2]['message']);
$this->assertSame('17', $output[2]['source_ids']);
$this->assertEmpty($output[0]['destination_ids']);
// Only one invalid ID.
$this->drush('migrate:messages', ['test_migration'], ['format' => 'json', 'idlist' => '100']);
$output = $this->getOutputFromJSON();
$this->assertCount(0, $output);
// Only one valid ID.
$this->drush('migrate:messages', ['test_migration'], ['format' => 'json', 'idlist' => '2']);
$output = $this->getOutputFromJSON();
// @see \Drupal\woot\Plugin\migrate\process\TestFailProcess::transform()
$this->assertCount(1, $output);
$this->assertEquals(1, $output[0]['level']);
$this->assertSame('2', $output[0]['source_ids']);
$this->assertEmpty($output[0]['destination_ids']);
$this->assertStringContainsString('ID 2 should fail', $output[0]['message']);
// Three valid IDs, two with data, one without, and one invalid ID.
$this->drush('migrate:messages', ['test_migration'], ['format' => 'json', 'idlist' => '1,2,9,100']);
$output = $this->getOutputFromJSON();
// @see \Drupal\woot\Plugin\migrate\process\TestFailProcess::transform()
$this->assertCount(2, $output);
$this->assertEquals(1, $output[0]['level']);
$this->assertSame('2', $output[0]['source_ids']);
$this->assertEmpty($output[0]['destination_ids']);
$this->assertStringContainsString('ID 2 should fail', $output[0]['message']);
$this->assertEquals(1, $output[1]['level']);
$this->assertSame('9', $output[1]['source_ids']);
$this->assertEmpty($output[0]['destination_ids']);
$this->assertStringContainsString('ID 9 should fail', $output[1]['message']);
$this->drush('migrate:fields-source', ['test_migration'], ['format' => 'json']);
$output = $this->getOutputFromJSON();
$this->assertEquals('id', $output[0]['machine_name']);
$this->assertEquals('id', $output[0]['description']);
$this->assertEquals('name', $output[1]['machine_name']);
$this->assertEquals('name', $output[1]['description']);
}
/**
* Regression test when importing with --limit and --feedback.
*
* @see https://www.drupal.org/project/migrate_tools/issues/2919108
*/
public function testImportingWithLimitAndFeedback(): void
{
// Set the test_migration source to 300 records.
// @see woot_migration_plugins_alter()
$this->drush('state:set', ['woot.migrate_runner.source_data_amount', 300]);
$this->drush('migrate:import', ['test_migration'], [
'feedback' => 20,
'limit' => 199,
'no-progress' => null,
]);
$importOutput = array_values(array_filter(array_map('trim', $this->getErrorOutputAsList()), function (string $line): bool {
return strpos($line, '[notice]') === 0;
}));
$this->assertCount(10, $importOutput);
foreach ($importOutput as $delta => $outputLine) {
if ($delta < 9) {
$this->assertMatchesRegularExpression("/^\[notice\] Processed 20 items \(20 created, 0 updated, 0 failed, 0 ignored\) in \d+(\.\d+)? seconds \(\d+(\.\d+)?\/min\) \- continuing with 'test_migration'/", $outputLine);
} else {
// The last log entry is different.
$this->assertMatchesRegularExpression("/^\[notice\] Processed 19 items \(19 created, 0 updated, 0 failed, 0 ignored\) in \d+(\.\d+)? seconds \(\d+(\.\d+)?\/min\) \- done with 'test_migration'/", $outputLine);
}
}
$this->drush('migrate:status', ['test_migration'], ['format' => 'json']);
$output = $this->getOutputFromJSON(0);
// Check also stats.
$this->assertSame(300, $output['total']);
$this->assertSame('199 (66.3%)', $output['imported']);
$this->assertSame(101, $output['unprocessed']);
}
/**
* Regression test when importing with --update and --idlist.
*
* @covers ::executeMigration
* @see https://www.drupal.org/project/migrate_tools/issues/3015386
*/
public function testImportingWithUpdateAndIdlist(): void
{
// Check a migration limited by ID.
$this->drush('migrate:import', ['test_migration'], ['idlist' => '1']);
$this->drush('migrate:status', ['test_migration'], [
'format' => 'json',
]);
$this->assertSame('1 (50%)', $this->getOutputFromJSON(0)['imported']);
// Migrate all.
$this->drush('migrate:import', ['test_migration']);
$this->drush('migrate:status', ['test_migration'], [
'format' => 'json',
]);
$this->assertSame('2 (100%)', $this->getOutputFromJSON(0)['imported']);
// Try to reimport with --idlist and --update.
$this->drush('migrate:import', ['test_migration'], [
'idlist' => '1',
'update' => null,
]);
$this->drush('migrate:status', ['test_migration'], [
'fields' => 'needing_update',
'format' => 'json',
]);
// Check that no row needs update.
$this->assertSame(0, $this->getOutputFromJSON(0)['needing_update']);
}
/**
* @covers \Drush\Drupal\Migrate\MigrateExecutable::initProgressBar
*/
public function testCommandProgressBar(): void
{
$this->drush('state:set', ['woot.migrate_runner.source_data_amount', 50]);
// Check an import and rollback with progress bar.
$this->drush('migrate:import', ['test_migration']);
$this->assertProgressBar();
$this->drush('migrate:rollback', ['test_migration']);
$this->assertProgressBar();
// Check that progress bar won't show when --no-progress is passed.
$this->drush('migrate:import', ['test_migration'], ['no-progress' => null]);
$this->assertNoProgressBar();
$this->drush('migrate:rollback', ['test_migration'], ['no-progress' => null]);
$this->assertNoProgressBar();
// Check that progress bar won't show when --feedback is passed.
$this->drush('migrate:import', ['test_migration'], ['feedback' => 10]);
$this->assertNoProgressBar();
$this->drush('migrate:rollback', ['test_migration'], ['feedback' => 10]);
$this->assertNoProgressBar();
// Set the 'test_migration' source plugin to skip count.
// @see woot_migration_plugins_alter()
$this->drush('state:set', ['woot.migrate_runner.progress_bar_skip_count', true]);
// Get fresh plugin definitions.
drupal_flush_all_caches();
// Check that progress bar won't show when the source skips count.
$this->drush('migrate:import', ['test_migration']);
$this->assertNoProgressBar();
$this->drush('migrate:rollback', ['test_migration']);
$this->assertNoProgressBar();
}
/**
* Asserts that the command exposes a progress bar.
*/
protected function assertProgressBar(): void
{
$this->progressBarAssertionHelper(true);
}
/**
* Asserts that the command doesn't expose a progress bar.
*/
protected function assertNoProgressBar(): void
{
$this->progressBarAssertionHelper(false);
}
/**
* @param bool $assertHasProgressBar
*/
protected function progressBarAssertionHelper(bool $assertHasProgressBar): void
{
static $expectedProgressBars = [
'5/50 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░] 10%',
'10/50 [▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░] 20%',
'15/50 [▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░] 30%',
'20/50 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░] 40%',
'25/50 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░] 50%',
'30/50 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░] 60%',
'35/50 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░] 70%',
'40/50 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░] 80%',
'45/50 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░] 90%',
'50/50 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%',
];
// On Windows systems the new line delimiter is a CR+LF (\r\n)
// sequence instead of LF (\n) as it is on *nix systems.
$actualOutput = str_replace("\r\n", "\n", $this->getErrorOutputRaw());
if ($this->isWindows()) {
// Only standard bar is supported.
array_walk($expectedProgressBars, function (string &$bar): void {
$bar = str_replace('▓░', '=>', $bar);
$bar = str_replace('▓', '=', $bar);
$bar = str_replace('░', '-', $bar);
});
}
foreach ($expectedProgressBars as $expectedProgressBar) {
if ($assertHasProgressBar) {
$this->assertStringContainsString($expectedProgressBar, $actualOutput);
} else {
$this->assertStringNotContainsString($expectedProgressBar, $actualOutput);
}
}
}
/**
* {@inheritdoc}
*/
protected function tearDown(): void
{
// Cleanup any created content.
$this->drush('entity:delete', ['node']);
// Uninstalling Migrate module doesn't automatically drop the tables.
// @see https://www.drupal.org/project/drupal/issues/2713327
$migrations = \Drupal::service('plugin.manager.migration')->createInstances([]);
array_walk($migrations, function (MigrationInterface $migration): void {
$migration->getIdMap()->destroy();
});
// Uninstall test modules.
$this->drush('pm:uninstall', ['migrate', 'node', 'woot']);
// Cleanup any testing state vars.
$state = \Drupal::state();
foreach (['trigger_failures', 'source_data_amount', 'removed_source_rows', 'progress_bar_skip_count'] as $var) {
$state->delete("woot.migrate_runner.$var");
}
parent::tearDown();
}
}