DataParserPluginBaseTest.php in Migrate Plus 8.5
File
tests/src/Unit/DataParserPluginBaseTest.php
View source
<?php
namespace Drupal\Tests\migrate_plus\Unit;
use Drupal\migrate_plus\DataParserPluginBase;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
class DataParserPluginBaseTest extends MigrateTestCase {
public function testNextSourceWithOneUrl() : void {
$parser = $this
->getMockedDataParser();
$parser
->expects($this
->once())
->method('openSourceUrl')
->willReturn(TRUE);
$this
->assertTrue($parser
->nextSource());
}
public function testNextSourceWithoutUrls() : void {
$config = [
'urls' => [],
];
$parser = $this
->getMockedDataParser($config);
$parser
->expects($this
->never())
->method('openSourceUrl');
$this
->assertFalse($parser
->nextSource());
}
public function testCountWithoutUrls() : void {
$config = [
'urls' => [],
];
$parser = $this
->getMockedDataParser($config);
$parser
->expects($this
->never())
->method('openSourceUrl');
$this
->assertEquals(0, $parser
->count());
}
protected function getMockedDataParser(array $configuration = []) {
$configuration += [
'urls' => [
'http://example.org/data_parser_test',
],
'item_selector' => 0,
];
$plugin_id = 'foo';
$plugin_definition = [
'id' => 'foo',
'title' => 'Foo',
];
return $this
->getMockBuilder(DataParserPluginBaseMock::class)
->setConstructorArgs([
$configuration,
$plugin_id,
$plugin_definition,
])
->setMethods([
'openSourceUrl',
])
->getMockForAbstractClass();
}
}
abstract class DataParserPluginBaseMock extends DataParserPluginBase {
public function nextSource() {
return parent::nextSource();
}
}