class CSVFileObjectTest in Migrate Source CSV 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/CSVFileObjectTest.php \Drupal\Tests\migrate_source_csv\Unit\CSVFileObjectTest
@coversDefaultClass \Drupal\migrate_source_csv\CSVFileObject
@group migrate_source_csv
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate_source_csv\Unit\CSVUnitTestCase
- class \Drupal\Tests\migrate_source_csv\Unit\CSVFileObjectTest
- class \Drupal\Tests\migrate_source_csv\Unit\CSVUnitTestCase
Expanded class hierarchy of CSVFileObjectTest
File
- tests/
src/ Unit/ CSVFileObjectTest.php, line 16 - Code for CSVFileObjectTest.php.
Namespace
Drupal\Tests\migrate_source_csv\UnitView source
class CSVFileObjectTest extends CSVUnitTestCase {
/**
* The CSV file object.
*
* @var \Drupal\migrate_source_csv\CSVFileObject
*/
protected $csvFileObject;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->csvFileObject = new CSVFileObject($this->happyPath);
}
/**
* Tests that the construction appropriately creates a CSVFileObject.
*
* @test
*
* @covers ::__construct
*/
public function create() {
$this
->assertInstanceOf(CSVFileObject::class, $this->csvFileObject);
$flags = CSVFileObject::READ_CSV | CSVFileObject::READ_AHEAD | CSVFileObject::DROP_NEW_LINE | CSVFileObject::SKIP_EMPTY;
$this
->assertSame($flags, $this->csvFileObject
->getFlags());
}
/**
* Tests that the header row count is correctly set.
*
* @test
*
* @covers ::setHeaderRowCount
*/
public function setHeaderRowCount() {
$expected = 2;
$this->csvFileObject
->setHeaderRowCount($expected);
return $this->csvFileObject
->getHeaderRowCount();
}
/**
* Tests that the header row count is correctly returned.
*
* @test
*
* @depends setHeaderRowCount
*
* @covers ::getHeaderRowCount
*/
public function getHeaderRowCount($actual) {
$expected = 2;
$this
->assertEquals($expected, $actual);
}
/**
* Tests that line count is correct.
*
* @test
*
* @covers ::count
*/
public function countLines() {
$expected = 15;
$this->csvFileObject
->setHeaderRowCount(1);
$actual = $this->csvFileObject
->count();
$this
->assertEquals($expected, $actual);
}
/**
* Tests that the current row is correctly returned.
*
* @test
*
* @covers ::current
* @covers ::rewind
* @covers ::getColumnNames
* @covers ::setColumnNames
*/
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());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CSVFileObjectTest:: |
protected | property | The CSV file object. | |
CSVFileObjectTest:: |
public | function | Tests that line count is correct. | |
CSVFileObjectTest:: |
public | function | Tests that the construction appropriately creates a CSVFileObject. | |
CSVFileObjectTest:: |
public | function | Tests that the current row is correctly returned. | |
CSVFileObjectTest:: |
public | function | Tests that the header row count is correctly returned. | |
CSVFileObjectTest:: |
public | function | Tests that the header row count is correctly set. | |
CSVFileObjectTest:: |
protected | function |
Overrides CSVUnitTestCase:: |
|
CSVUnitTestCase:: |
protected | property | The happy path file url. | |
CSVUnitTestCase:: |
protected | property | The un-happy path file url. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |