class DrupalSqlBaseTest
Same name in other branches
- 9 core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\DrupalSqlBaseTest
- 8.9.x core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\DrupalSqlBaseTest
- 11.x core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\DrupalSqlBaseTest
@coversDefaultClass \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase @group migrate_drupal
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\migrate\Unit\MigrateTestCase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\migrate_drupal\Unit\source\DrupalSqlBaseTest extends \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of DrupalSqlBaseTest
File
-
core/
modules/ migrate_drupal/ tests/ src/ Unit/ source/ DrupalSqlBaseTest.php, line 16
Namespace
Drupal\Tests\migrate_drupal\Unit\sourceView source
class DrupalSqlBaseTest extends MigrateTestCase {
/**
* Define bare minimum migration configuration.
*/
protected $migrationConfiguration = [
'id' => 'DrupalSqlBase',
];
/**
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
*/
protected $base;
/**
* The plugin definition.
*
* @var array
*/
protected $pluginDefinition = [];
/**
* Mock StateInterface.
*
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $state;
/**
* Mock entity type manager.
*
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* Minimum database contents needed to test DrupalSqlBase.
*/
protected $databaseContents = [
'system' => [
[
'filename' => 'sites/all/modules/module1',
'name' => 'module1',
'type' => 'module',
'status' => 0,
'schema_version' => -1,
],
],
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->pluginDefinition['requirements_met'] = TRUE;
$this->pluginDefinition['source_module'] = 'module1';
$this->state = $this->createMock('Drupal\\Core\\State\\StateInterface');
$this->entityTypeManager = $this->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
}
/**
* @covers ::checkRequirements
*/
public function testSourceProviderNotActive() : void {
$plugin = new TestDrupalSqlBase([], 'placeholder_id', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager);
$plugin->setDatabase($this->getDatabase($this->databaseContents));
$this->expectException(RequirementsException::class);
$this->expectExceptionMessage('The module module1 is not enabled in the source site.');
try {
$plugin->checkRequirements();
} catch (RequirementsException $e) {
// Ensure requirements are set on the exception.
$this->assertEquals([
'source_module' => 'module1',
], $e->getRequirements());
// Re-throw so PHPUnit can assert the exception.
throw $e;
}
}
/**
* @covers ::checkRequirements
*/
public function testSourceDatabaseError() : void {
$plugin = new TestDrupalSqlBase([], 'test', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager);
$this->expectException(RequirementsException::class);
$this->expectExceptionMessage('No database connection configured for source plugin test');
$plugin->checkRequirements();
}
/**
* @covers ::checkRequirements
*
* @param bool $success
* True if this test will not throw an exception.
* @param null|string $minimum_version
* The minimum version declared in the configuration of a source plugin.
* @param string $schema_version
* The schema version for the source module declared in a source plugin.
*
* @dataProvider providerMinimumVersion
*/
public function testMinimumVersion($success, $minimum_version, $schema_version) : void {
$this->pluginDefinition['minimum_version'] = $minimum_version;
$this->databaseContents['system'][0]['status'] = 1;
$this->databaseContents['system'][0]['schema_version'] = $schema_version;
$plugin = new TestDrupalSqlBase([], 'test', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager);
$plugin->setDatabase($this->getDatabase($this->databaseContents));
$this->assertSame([], $plugin->fields());
if (!$success) {
$this->expectException(RequirementsException::class);
$this->expectExceptionMessage("Required minimum version {$minimum_version}");
}
$plugin->checkRequirements();
}
/**
* Provides data for testMinimumVersion.
*/
public static function providerMinimumVersion() {
return [
'minimum less than schema' => [
TRUE,
'7000',
'7001',
],
'same version' => [
TRUE,
'7001',
'7001',
],
'minimum greater than schema' => [
FALSE,
'7005',
'7001',
],
'schema version 0' => [
FALSE,
'7000',
'0',
],
'schema version -1' => [
FALSE,
'7000',
'-1',
],
'minimum not set' => [
TRUE,
NULL,
'-1',
],
];
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
DrupalSqlBaseTest::$base | protected | property | ||||
DrupalSqlBaseTest::$databaseContents | protected | property | Minimum database contents needed to test DrupalSqlBase. | |||
DrupalSqlBaseTest::$entityTypeManager | protected | property | Mock entity type manager. | |||
DrupalSqlBaseTest::$migrationConfiguration | protected | property | Define bare minimum migration configuration. | Overrides MigrateTestCase::$migrationConfiguration | ||
DrupalSqlBaseTest::$pluginDefinition | protected | property | The plugin definition. | |||
DrupalSqlBaseTest::$state | protected | property | Mock StateInterface. | |||
DrupalSqlBaseTest::providerMinimumVersion | public static | function | Provides data for testMinimumVersion. | |||
DrupalSqlBaseTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
DrupalSqlBaseTest::testMinimumVersion | public | function | @covers ::checkRequirements | |||
DrupalSqlBaseTest::testSourceDatabaseError | public | function | @covers ::checkRequirements | |||
DrupalSqlBaseTest::testSourceProviderNotActive | public | function | @covers ::checkRequirements | |||
MigrateTestCase::$idMap | protected | property | The migration ID map. | |||
MigrateTestCase::$migrationStatus | protected | property | Local store for mocking setStatus()/getStatus(). | |||
MigrateTestCase::createSchemaFromRow | protected | function | Generates a table schema from a row. | |||
MigrateTestCase::getDatabase | protected | function | Gets an SQLite database connection object for use in tests. | |||
MigrateTestCase::getMigration | protected | function | Retrieves a mocked migration. | |||
MigrateTestCase::getValue | protected | function | Gets the value on a row for a given key. | |||
MigrateTestCase::queryResultTest | public | function | Tests a query. | |||
MigrateTestCase::retrievalAssertHelper | protected | function | Asserts tested values during test retrieval. | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.