Issue #2918837 by heddn, neclimdul, phenaproxima, quietone, Gábor Hojtsy: SqlBase throws fatal error when extended directly

8.5.x
Gabor Hojtsy 2018-01-12 18:00:29 +01:00
parent 1e2583bb31
commit 358989eaa1
3 changed files with 9 additions and 6 deletions

View File

@ -216,7 +216,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
/** /**
* Initializes the iterator with the source data. * Initializes the iterator with the source data.
* *
* @return array * @return \Iterator
* An array of the data for this source. * An array of the data for this source.
*/ */
abstract protected function initializeIterator(); abstract protected function initializeIterator();

View File

@ -346,7 +346,9 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
if (($this->batchSize > 0)) { if (($this->batchSize > 0)) {
$this->query->range($this->batch * $this->batchSize, $this->batchSize); $this->query->range($this->batch * $this->batchSize, $this->batchSize);
} }
return new \IteratorIterator($this->query->execute()); $statement = $this->query->execute();
$statement->setFetchMode(\PDO::FETCH_ASSOC);
return new \IteratorIterator($statement);
} }
/** /**

View File

@ -9,6 +9,7 @@ namespace Drupal\Tests\migrate\Kernel;
use Drupal\Core\Database\Query\ConditionInterface; use Drupal\Core\Database\Query\ConditionInterface;
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Database\StatementInterface;
use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Exception\RequirementsException;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\migrate\Plugin\migrate\source\SqlBase; use Drupal\migrate\Plugin\migrate\source\SqlBase;
@ -149,10 +150,10 @@ class SqlBaseTest extends MigrateTestBase {
$source->getHighWaterStorage()->set($this->migration->id(), $high_water); $source->getHighWaterStorage()->set($this->migration->id(), $high_water);
} }
$query_result = new \ArrayIterator($query_result); $statement = $this->createMock(StatementInterface::class);
$statement->expects($this->atLeastOnce())->method('setFetchMode')->with(\PDO::FETCH_ASSOC);
$query = $this->getMock(SelectInterface::class); $query = $this->createMock(SelectInterface::class);
$query->method('execute')->willReturn($query_result); $query->method('execute')->willReturn($statement);
$query->expects($this->atLeastOnce())->method('orderBy')->with('order', 'ASC'); $query->expects($this->atLeastOnce())->method('orderBy')->with('order', 'ASC');
$condition_group = $this->getMock(ConditionInterface::class); $condition_group = $this->getMock(ConditionInterface::class);