function MigrationConfigurationTraitTest::testGetLegacyDrupalVersion

Same name in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Unit/MigrationConfigurationTraitTest.php \Drupal\Tests\migrate_drupal\Unit\MigrationConfigurationTraitTest::testGetLegacyDrupalVersion()
  2. 11.x core/modules/migrate_drupal/tests/src/Unit/MigrationConfigurationTraitTest.php \Drupal\Tests\migrate_drupal\Unit\MigrationConfigurationTraitTest::testGetLegacyDrupalVersion()

@covers ::getLegacyDrupalVersion @dataProvider providerTestGetLegacyDrupalVersion

File

core/modules/migrate_drupal/tests/src/Unit/MigrationConfigurationTraitTest.php, line 21

Class

MigrationConfigurationTraitTest
@coversDefaultClass \Drupal\migrate_drupal\MigrationConfigurationTrait @group migrate_drupal

Namespace

Drupal\Tests\migrate_drupal\Unit

Code

public function testGetLegacyDrupalVersion($expected_version_string, $schema_version, $exception, $system_table_exists) : void {
    if ($schema_version) {
        $statement = $this->createMock('\\Drupal\\Core\\Database\\StatementInterface');
        $statement->expects($this->any())
            ->method('fetchField')
            ->willReturn($schema_version);
    }
    $schema = $this->createMock('\\Drupal\\Core\\Database\\Schema');
    $schema->expects($this->once())
        ->method('tableExists')
        ->willReturn($system_table_exists);
    $connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
        ->disableOriginalConstructor()
        ->getMock();
    if ($exception) {
        $connection->expects($this->any())
            ->method('query')
            ->willThrowException($exception);
    }
    else {
        $connection->expects($this->any())
            ->method('query')
            ->willReturn($statement);
    }
    $connection->expects($this->any())
        ->method('schema')
        ->willReturn($schema);
    $actual_version_string = TestMigrationConfigurationTrait::getLegacyDrupalVersion($connection);
    $this->assertSame($expected_version_string, $actual_version_string);
}

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