class TestSqlBase

Same name in this branch
  1. 9 core/modules/migrate/tests/src/Unit/SqlBaseTest.php \Drupal\Tests\migrate\Unit\TestSqlBase
Same name and namespace in other branches
  1. 11.x core/modules/migrate/tests/src/Unit/SqlBaseTest.php \Drupal\Tests\migrate\Unit\TestSqlBase
  2. 11.x core/modules/migrate/tests/src/Kernel/SqlBaseTest.php \Drupal\Tests\migrate\Kernel\TestSqlBase
  3. 10 core/modules/migrate/tests/src/Unit/SqlBaseTest.php \Drupal\Tests\migrate\Unit\TestSqlBase
  4. 10 core/modules/migrate/tests/src/Kernel/SqlBaseTest.php \Drupal\Tests\migrate\Kernel\TestSqlBase
  5. 8.9.x core/modules/migrate/tests/src/Unit/SqlBaseTest.php \Drupal\Tests\migrate\Unit\TestSqlBase
  6. 8.9.x core/modules/migrate/tests/src/Kernel/SqlBaseTest.php \Drupal\Tests\migrate\Kernel\TestSqlBase

A dummy source to help with testing SqlBase.

@package Drupal\migrate\Plugin\migrate\source

Hierarchy

Expanded class hierarchy of TestSqlBase

File

core/modules/migrate/tests/src/Kernel/SqlBaseTest.php, line 186

Namespace

Drupal\Tests\migrate\Kernel
View source
class TestSqlBase extends SqlBase {
  
  /**
   * The query to execute.
   *
   * @var \Drupal\Core\Database\Query\SelectInterface
   */
  protected $query;
  
  /**
   * Overrides the constructor so we can create one easily.
   *
   * @param array $configuration
   *   The plugin instance configuration.
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   *   (optional) The migration being run.
   */
  public function __construct(array $configuration = [], MigrationInterface $migration = NULL) {
    parent::__construct($configuration, 'sql_base', [], $migration, \Drupal::state());
  }
  
  /**
   * Gets the database without caching it.
   */
  public function getDatabase() {
    $this->database = NULL;
    return parent::getDatabase();
  }
  
  /**
   * Allows us to set the configuration from a test.
   *
   * @param array $config
   *   The config array.
   */
  public function setConfiguration($config) {
    $this->configuration = $config;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getIds() {
    return [];
  }
  
  /**
   * {@inheritdoc}
   */
  public function fields() {
    throw new \RuntimeException(__METHOD__ . " not implemented for " . __CLASS__);
  }
  
  /**
   * {@inheritdoc}
   */
  public function query() {
    return $this->query;
  }
  
  /**
   * Sets the query to execute.
   *
   * @param \Drupal\Core\Database\Query\SelectInterface $query
   *   The query to execute.
   */
  public function setQuery(SelectInterface $query) {
    $this->query = $query;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.