Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
migrate_source_csv
Commits
0be34471
Commit
0be34471
authored
Oct 22, 2018
by
heddn
Committed by
heddn
Oct 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3004043
by dhirendra.mishra, heddn, hardikpandya: Coding standards
parent
2a8910a3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
25 deletions
+28
-25
src/CSVFileObject.php
src/CSVFileObject.php
+1
-1
src/Plugin/migrate/source/CSV.php
src/Plugin/migrate/source/CSV.php
+5
-1
tests/src/Unit/CSVUnitBase.php
tests/src/Unit/CSVUnitBase.php
+2
-0
tests/src/Unit/Plugin/migrate/source/CSVUnitTest.php
tests/src/Unit/Plugin/migrate/source/CSVUnitTest.php
+20
-23
No files found.
src/CSVFileObject.php
View file @
0be34471
...
...
@@ -17,7 +17,7 @@ class CSVFileObject extends \SplFileObject {
/**
* The number of rows in the CSV file before the data starts.
*
* @var int
eger
* @var int
*/
protected
$headerRowCount
=
0
;
...
...
src/Plugin/migrate/source/CSV.php
View file @
0be34471
...
...
@@ -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
getI
D
s
()
{
public
function
getI
d
s
()
{
$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
[];
}
}
tests/src/Unit/CSVUnitBase.php
View file @
0be34471
<?php
namespace
Drupal\Tests\migrate_source_csv\Unit
;
use
Drupal\Tests\UnitTestCase
;
...
...
@@ -101,4 +102,5 @@ EOD;
->
withContent
(
$multiLineContent
)
->
url
();
}
}
tests/src/Unit/Plugin/migrate/source/CSVUnitTest.php
View file @
0be34471
...
...
@@ -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
testConfigurableC
SV
FileObject
()
{
public
function
testConfigurableC
sv
FileObject
()
{
$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
testConfigurableC
SV
FileObjectFlags
()
{
public
function
testConfigurableC
sv
FileObjectFlags
()
{
$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
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment