public function CSVFileObjectTest::current in Migrate Source CSV 8
Tests that the current row is correctly returned.
@test
@covers ::current @covers ::rewind @covers ::getColumnNames @covers ::setColumnNames
File
- tests/
src/ Unit/ CSVFileObjectTest.php, line 99 - Code for CSVFileObjectTest.php.
Class
- CSVFileObjectTest
- @coversDefaultClass \Drupal\migrate_source_csv\CSVFileObject
Namespace
Drupal\Tests\migrate_source_csv\UnitCode
public function current() {
$column_names = [
[
'id' => 'Identifier',
],
[
'first_name' => 'First Name',
],
[
'last_name' => 'Last Name',
],
[
'email' => 'Email',
],
[
'country' => 'Country',
],
[
'ip_address' => 'IP Address',
],
];
$columns = [];
foreach ($column_names as $values) {
$columns[] = key($values);
}
$row = [
'1',
'Justin',
'Dean',
'jdean0@example.com',
'Indonesia',
'60.242.130.40',
];
$csv_file_object = $this->csvFileObject;
$csv_file_object
->rewind();
$current = $csv_file_object
->current();
$this
->assertArrayEquals($columns, $current);
$csv_file_object
->setHeaderRowCount(1);
$csv_file_object
->rewind();
$current = $csv_file_object
->current();
$this
->assertArrayEquals($row, $current);
$csv_file_object
->setColumnNames($column_names);
$csv_file_object
->rewind();
$current = $csv_file_object
->current();
$this
->assertArrayEquals($columns, array_keys($current));
$this
->assertArrayEquals($row, array_values($current));
$this
->assertArrayEquals($column_names, $csv_file_object
->getColumnNames());
}