From 4276e5113154e18c5113097c8e61249a3311952c Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Tue, 5 May 2020 08:58:01 -0500
Subject: [PATCH] Issue #3107472 by ravi.shankar, alexpott, kishor_kolekar,
 jibran: DbDumpCommand should not hardcode the version string

---
 core/lib/Drupal/Core/Command/DbDumpCommand.php                | 4 +++-
 core/lib/Drupal/Core/Command/DbToolsApplication.php           | 2 +-
 .../system/tests/src/Kernel/Scripts/DbDumpCommandTest.php     | 2 ++
 .../tests/src/Kernel/Scripts/DbToolsApplicationTest.php       | 1 +
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/core/lib/Drupal/Core/Command/DbDumpCommand.php b/core/lib/Drupal/Core/Command/DbDumpCommand.php
index ae07e3f32fe4..fdbe3f5f964e 100644
--- a/core/lib/Drupal/Core/Command/DbDumpCommand.php
+++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php
@@ -93,6 +93,8 @@ protected function generateScript(Connection $connection, array $schema_only = [
       $tables .= $this->getTableScript($table, $schema, $data);
     }
     $script = $this->getTemplate();
+    // Substitute in the version.
+    $script = str_replace('{{VERSION}}', \Drupal::VERSION, $script);
     // Substitute in the tables.
     $script = str_replace('{{TABLES}}', trim($tables), $script);
     return trim($script);
@@ -395,7 +397,7 @@ protected function getTemplate() {
  * @file
  * A database agnostic dump for testing purposes.
  *
- * This file was generated by the Drupal 8.0 db-tools.php script.
+ * This file was generated by the Drupal {{VERSION}} db-tools.php script.
  */
 
 use Drupal\Core\Database\Database;
diff --git a/core/lib/Drupal/Core/Command/DbToolsApplication.php b/core/lib/Drupal/Core/Command/DbToolsApplication.php
index aa48e1c57e08..7ce24272b055 100644
--- a/core/lib/Drupal/Core/Command/DbToolsApplication.php
+++ b/core/lib/Drupal/Core/Command/DbToolsApplication.php
@@ -13,7 +13,7 @@ class DbToolsApplication extends Application {
    * {@inheritdoc}
    */
   public function __construct() {
-    parent::__construct('Database Tools', '8.0.x');
+    parent::__construct('Database Tools', \Drupal::VERSION);
   }
 
   /**
diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php
index 887ba8a11766..a571d95b6cca 100644
--- a/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php
+++ b/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php
@@ -54,6 +54,8 @@ public function testDbDumpCommand() {
     $this->assertStringContainsString("'path' => 'test", $output, 'Insert path field found');
     $this->assertStringContainsString("'pattern_outline' => 'test", $output, 'Insert pattern_outline field found');
     $this->assertStringContainsString("// @codingStandardsIgnoreFile", $output);
+    $version = \Drupal::VERSION;
+    $this->assertStringContainsString("This file was generated by the Drupal {$version} db-tools.php script.", $output);
   }
 
   /**
diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbToolsApplicationTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbToolsApplicationTest.php
index 6bf39aafc1d7..47c5f6aac9de 100644
--- a/core/modules/system/tests/src/Kernel/Scripts/DbToolsApplicationTest.php
+++ b/core/modules/system/tests/src/Kernel/Scripts/DbToolsApplicationTest.php
@@ -22,6 +22,7 @@ public function testDumpCommandRegistration() {
     $application = new DbToolsApplication();
     $command = $application->find('dump');
     $this->assertInstanceOf('\Drupal\Core\Command\DbDumpCommand', $command);
+    $this->assertSame(\Drupal::VERSION, $application->getVersion());
   }
 
   /**
-- 
GitLab