Commit 0be34471 authored by heddn's avatar heddn Committed by heddn

Issue #3004043 by dhirendra.mishra, heddn, hardikpandya: Coding standards

parent 2a8910a3
......@@ -17,7 +17,7 @@ class CSVFileObject extends \SplFileObject {
/**
* The number of rows in the CSV file before the data starts.
*
* @var integer
* @var int
*/
protected $headerRowCount = 0;
......
......@@ -95,7 +95,10 @@ class CSV extends SourcePluginBase implements ConfigurablePluginInterface {
}
/**
* Setup the file.
*
* @return \SplFileObject
* Returns the file object.
*/
protected function setupFile() {
// Set basics of CSV behavior based on configuration.
......@@ -132,7 +135,7 @@ class CSV extends SourcePluginBase implements ConfigurablePluginInterface {
/**
* {@inheritdoc}
*/
public function getIDs() {
public function getIds() {
$ids = [];
foreach ($this->getConfiguration()['keys'] as $delta => $value) {
if (is_array($value)) {
......@@ -213,4 +216,5 @@ class CSV extends SourcePluginBase implements ConfigurablePluginInterface {
public function calculateDependencies() {
return [];
}
}
<?php
namespace Drupal\Tests\migrate_source_csv\Unit;
use Drupal\Tests\UnitTestCase;
......@@ -101,4 +102,5 @@ EOD;
->withContent($multiLineContent)
->url();
}
}
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\migrate_source_csv\Unit\Plugin\migrate\source;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_source_csv\CSVFileObject;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;
......@@ -70,27 +71,20 @@ class CSVUnitTest extends CSVUnitBase {
/**
* Tests that a missing path will throw an exception.
*
* @expectedException \Drupal\migrate\MigrateException
*
* @expectedExceptionMessage You must declare the "path" to the source CSV file in your source settings.
*/
public function testMigrateExceptionPathMissing() {
$this->setExpectedException(MigrateException::class, 'You must declare the "path" to the source CSV file in your source settings.');
new CSV([], $this->pluginId, $this->pluginDefinition, $this->migration);
}
/**
* Tests that missing keys will throw an exception.
*
* @expectedException \Drupal\migrate\MigrateException
*
* @expectedExceptionMessage You must declare "keys" as a unique array of fields in your source settings.
*/
public function testMigrateExceptionKeysMissing() {
$configuration = [
'path' => $this->happyPath,
];
$this->setExpectedException(MigrateException::class, 'You must declare "keys" as a unique array of fields in your source settings.');
new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
}
......@@ -230,6 +224,7 @@ class CSVUnitTest extends CSVUnitBase {
* @covers ::getIds
*/
public function testGetIdsComplex() {
// @codingStandardsIgnoreStart
$configuration = [
'path' => $this->happyPath,
'keys' => [
......@@ -241,7 +236,7 @@ class CSVUnitTest extends CSVUnitBase {
],
'header_row_count' => 1,
];
// @codingStandardsIgnoreEnd
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$expected = [
......@@ -291,11 +286,11 @@ class CSVUnitTest extends CSVUnitBase {
];
$expected = $fields + [
'last_name' => 'last_name',
'email' => 'email',
'country' => 'country',
'ip_address' => 'ip_address',
];
'last_name' => 'last_name',
'email' => 'email',
'country' => 'country',
'ip_address' => 'ip_address',
];
$csv = new CSV($configuration + ['fields' => $fields], $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertArrayEquals($expected, $csv->fields());
......@@ -305,9 +300,9 @@ class CSVUnitTest extends CSVUnitBase {
2 => ['first_name' => 'User first name'],
];
$csv = new CSV($configuration + [
'fields' => $fields,
'column_names' => $column_names,
], $this->pluginId, $this->pluginDefinition, $this->migration);
'fields' => $fields,
'column_names' => $column_names,
], $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertArrayEquals($fields, $csv->fields());
}
......@@ -316,12 +311,12 @@ class CSVUnitTest extends CSVUnitBase {
*
* @covers ::__construct
*/
public function testConfigurableCSVFileObject() {
public function testConfigurableCsvFileObject() {
$configuration = [
'path' => $this->happyPath,
'keys' => ['id'],
'header_row_count' => 1,
'file_class' => FooCSVFileObject::class ,
'file_class' => FooCSVFileObject::class,
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
......@@ -337,7 +332,7 @@ class CSVUnitTest extends CSVUnitBase {
* @covers ::current
* @covers ::rewind
*/
public function testConfigurableCSVFileObjectFlags() {
public function testConfigurableCsvFileObjectFlags() {
$configuration = [
'path' => $this->multiLine,
'keys' => ['id'],
......@@ -376,10 +371,12 @@ class CSVUnitTest extends CSVUnitBase {
}
/**
* Class FooCSVFileObject
* Class FooCSVFileObject.
*
* Test file object class.
*
* @package Drupal\Tests\migrate_source_csv\Unit\Plugin\migrate\source
*/
class FooCSVFileObject extends CSVFileObject { }
class FooCSVFileObject extends CSVFileObject {
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment