diff --git a/src/CSVFileObject.php b/src/CSVFileObject.php index d0fb6f2..0a867a0 100644 --- a/src/CSVFileObject.php +++ b/src/CSVFileObject.php @@ -1,8 +1,4 @@ fileClass = empty($configuration['file_class']) ? CSVFileObject::class : $configuration['file_class']; + $this->fileClass = empty($configuration['file_class']) ? 'Drupal\migrate_source_csv\CSVFileObject' : $configuration['file_class']; } /** - * Return a string representing the source query. + * Return a string representing the source file path. * * @return string * The file path. diff --git a/tests/src/Kernel/Plugin/migrate/source/CSVKernelTest.php b/tests/src/Kernel/Plugin/migrate/source/CSVKernelTest.php new file mode 100644 index 0000000..7fd509c --- /dev/null +++ b/tests/src/Kernel/Plugin/migrate/source/CSVKernelTest.php @@ -0,0 +1,31 @@ +container->get('plugin.manager.migrate.source'); + $this->assertTrue($migrationSourceManager->hasDefinition('csv')); + } + +} diff --git a/tests/src/Unit/CSVFileObjectTest.php b/tests/src/Unit/CSVFileObjectTest.php index 2cf926d..f7daae1 100644 --- a/tests/src/Unit/CSVFileObjectTest.php +++ b/tests/src/Unit/CSVFileObjectTest.php @@ -1,8 +1,4 @@ csvFileObject->setHeaderRowCount($expected); - - return $this->csvFileObject->getHeaderRowCount(); - } - - /** * Tests that the header row count is correctly returned. * - * @depends setHeaderRowCount - * + * @covers ::setHeaderRowCount * @covers ::getHeaderRowCount */ - public function testGetHeaderRowCount($actual) { + public function testGetHeaderRowCount() { $expected = 2; + $this->csvFileObject->setHeaderRowCount($expected); + $actual = $this->csvFileObject->getHeaderRowCount(); $this->assertEquals($expected, $actual); } diff --git a/tests/src/Unit/CSVUnitTestCase.php b/tests/src/Unit/CSVUnitBase.php similarity index 94% rename from tests/src/Unit/CSVUnitTestCase.php rename to tests/src/Unit/CSVUnitBase.php index 270de60..3ab9822 100644 --- a/tests/src/Unit/CSVUnitTestCase.php +++ b/tests/src/Unit/CSVUnitBase.php @@ -1,20 +1,15 @@ url(); } - } diff --git a/tests/src/Unit/Plugin/migrate/source/CSVTest.php b/tests/src/Unit/Plugin/migrate/source/CSVUnitTest.php similarity index 88% rename from tests/src/Unit/Plugin/migrate/source/CSVTest.php rename to tests/src/Unit/Plugin/migrate/source/CSVUnitTest.php index c9aa05f..7e443ca 100644 --- a/tests/src/Unit/Plugin/migrate/source/CSVTest.php +++ b/tests/src/Unit/Plugin/migrate/source/CSVUnitTest.php @@ -1,22 +1,18 @@ pluginId = 'test csv migration'; $this->pluginDefinition = []; - $plugin = $this->prophesize(MigrationInterface::class); - $plugin->getIdMap() + $migration = $this->prophesize(MigrationInterface::class); + $migration->getIdMap() ->willReturn(NULL); - $this->plugin = $plugin->reveal(); + $this->migration = $migration->reveal(); } /** @@ -68,7 +62,7 @@ public function testCreate() { 'header_row_count' => 1, ]; - $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration); $this->assertInstanceOf(CSV::class, $csv); } @@ -81,7 +75,7 @@ public function testCreate() { * @expectedExceptionMessage You must declare the "path" to the source CSV file in your source settings. */ public function testMigrateExceptionPathMissing() { - new CSV([], $this->pluginId, $this->pluginDefinition, $this->plugin); + new CSV([], $this->pluginId, $this->pluginDefinition, $this->migration); } /** @@ -96,7 +90,7 @@ public function testMigrateExceptionKeysMissing() { 'path' => $this->happyPath, ]; - new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); + new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration); } /** @@ -111,7 +105,7 @@ public function testToString() { 'header_row_count' => 1, ]; - $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration); $this->assertEquals($configuration['path'], (string) $csv); } @@ -136,17 +130,17 @@ public function testInitializeIterator() { $config_enclosure = ['enclosure' => '%']; $config_escape = ['escape' => '`']; - $csv = new CSV($config_common + $config_delimiter, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($config_common + $config_delimiter, $this->pluginId, $this->pluginDefinition, $this->migration); $this->assertEquals(current($config_delimiter), $csv->initializeIterator() ->getCsvControl()[0]); $this->assertEquals('"', $csv->initializeIterator()->getCsvControl()[1]); - $csv = new CSV($config_common + $config_enclosure, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($config_common + $config_enclosure, $this->pluginId, $this->pluginDefinition, $this->migration); $this->assertEquals(',', $csv->initializeIterator()->getCsvControl()[0]); $this->assertEquals(current($config_enclosure), $csv->initializeIterator() ->getCsvControl()[1]); - $csv = new CSV($config_common + $config_delimiter + $config_enclosure + $config_escape, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($config_common + $config_delimiter + $config_enclosure + $config_escape, $this->pluginId, $this->pluginDefinition, $this->migration); $csv_file_object = $csv->initializeIterator(); $row = [ '1', @@ -160,7 +154,7 @@ public function testInitializeIterator() { $current = $csv_file_object->current(); $this->assertArrayEquals($row, $current); - $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration); $csv_file_object = $csv->initializeIterator(); $row = [ 'id' => '1', @@ -192,7 +186,7 @@ public function testInitializeIterator() { 2 => ['last_name' => 'User last name'], ], ]; - $csv = new CSV($configuration + $column_names, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration + $column_names, $this->pluginId, $this->pluginDefinition, $this->migration); $csv_file_object = $csv->initializeIterator(); $row = [ 'id' => '1', @@ -223,7 +217,7 @@ public function testGetIds() { 'header_row_count' => 1, ]; - $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration); $expected = ['id' => ['type' => 'string']]; $this->assertArrayEquals($expected, $csv->getIds()); @@ -252,8 +246,7 @@ public function testFields() { 'ip_address' => 'ip_address', ]; - $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); - $csv = new CSV($configuration + ['fields' => $fields], $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration + ['fields' => $fields], $this->pluginId, $this->pluginDefinition, $this->migration); $this->assertArrayEquals($expected, $csv->fields()); $column_names = [ @@ -263,7 +256,7 @@ public function testFields() { $csv = new CSV($configuration + [ 'fields' => $fields, 'column_names' => $column_names, - ], $this->pluginId, $this->pluginDefinition, $this->plugin); + ], $this->pluginId, $this->pluginDefinition, $this->migration); $this->assertArrayEquals($fields, $csv->fields()); } @@ -280,7 +273,7 @@ public function testConfigurableCSVFileObject() { 'file_class' => FooCSVFileObject::class , ]; - $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin); + $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration); $csv->initializeIterator(); $fileObject = $this->readAttribute($csv, 'file');