Commit ac9054a5 authored by catch's avatar catch
Browse files

fix: #3635165 Resolve InstallTasksTest PHPStan level 3 errors

By: mondrake
By: godotislate
(cherry picked from commit a4cbef85)
parent 3eb47271
Loading
Loading
Loading
Loading
Loading
−18
Changes for core/.phpstan-baseline.php: 0 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -35225,24 +35225,6 @@
	'count' => 2,
	'path' => __DIR__ . '/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql\\\\Install\\\\Tasks@anonymous/core/modules/mysql/tests/src/Unit/InstallTasksTest\\.php\\:31\\:\\:t\\(\\) should return Drupal\\\\Core\\\\StringTranslation\\\\TranslatableMarkup but returns string\\.$#',
	'identifier' => 'return.type',
	'count' => 1,
	'path' => __DIR__ . '/modules/mysql/tests/src/Unit/InstallTasksTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql\\\\Install\\\\Tasks@anonymous/core/modules/mysql/tests/src/Unit/InstallTasksTest\\.php\\:73\\:\\:t\\(\\) should return Drupal\\\\Core\\\\StringTranslation\\\\TranslatableMarkup but returns string\\.$#',
	'identifier' => 'return.type',
	'count' => 1,
	'path' => __DIR__ . '/modules/mysql/tests/src/Unit/InstallTasksTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Return type \\(null\\) of method Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql\\\\Install\\\\Tasks@anonymous/core/modules/mysql/tests/src/Unit/InstallTasksTest\\.php\\:73\\:\\:getConnection\\(\\) should be compatible with return type \\(Drupal\\\\Core\\\\Database\\\\Connection\\) of method Drupal\\\\Core\\\\Database\\\\Install\\\\Tasks\\:\\:getConnection\\(\\)$#',
	'identifier' => 'method.childReturnType',
	'count' => 1,
	'path' => __DIR__ . '/modules/mysql/tests/src/Unit/InstallTasksTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Call to an undefined method Drupal\\\\Core\\\\Database\\\\StatementInterface\\:\\:getClientStatement\\(\\)\\.$#',
	'identifier' => 'method.notFound',
+23 −80
Changes for core/modules/mysql/tests/src/Unit/InstallTasksTest.php: 23 added lines, 80 removed lines.
Original line number Diff line number Diff line
@@ -18,84 +18,6 @@
#[Group('Database')]
class InstallTasksTest extends UnitTestCase {

  /**
   * Creates a Tasks object for testing.
   *
   * @param \Drupal\mysql\Driver\Database\mysql\Connection $connection
   *   The database connection.
   *
   * @return \Drupal\mysql\Driver\Database\mysql\Install\Tasks
   *   A Tasks object.
   */
  private function createTasks(Connection $connection): Tasks {
    return new class($connection) extends Tasks {

      /**
       * The database connection.
       */
      private Connection $connection;

      public function __construct(Connection $connection) {
        $this->connection = $connection;
      }

      /**
       * {@inheritdoc}
       */
      protected function isConnectionActive(): bool {
        return TRUE;
      }

      /**
       * {@inheritdoc}
       */
      protected function getConnection(): Connection {
        return $this->connection;
      }

      /**
       * {@inheritdoc}
       */
      protected function t($string, array $args = [], array $options = []) {
        return $string;
      }

    };
  }

  /**
   * Creates a Tasks object for testing, without connection.
   *
   * @return \Drupal\mysql\Driver\Database\mysql\Install\Tasks
   *   A Tasks object.
   */
  private function createTasksNoConnection(): Tasks {
    return new class() extends Tasks {

      /**
       * {@inheritdoc}
       */
      protected function isConnectionActive(): bool {
        return FALSE;
      }

      /**
       * {@inheritdoc}
       */
      protected function getConnection(): null {
        return NULL;
      }

      /**
       * {@inheritdoc}
       */
      protected function t($string, array $args = [], array $options = []) {
        return $string;
      }

    };
  }

  /**
   * Tests name and minimum version.
   *
@@ -109,7 +31,19 @@ public function testNameAndMinimumVersion(bool $is_mariadb, string $expected_nam
      ->expects($this->exactly(2))
      ->method('isMariaDb')
      ->willReturn($is_mariadb);
    $tasks = $this->createTasks($connection);

    $tasks = $this->getMockBuilder(Tasks::class)
      ->onlyMethods(['getConnection', 't', 'isConnectionActive'])
      ->getMock();
    $tasks->expects($this->once())
      ->method('isConnectionActive')
      ->willReturn(TRUE);
    $tasks->expects($this->exactly(3))
      ->method('getConnection')
      ->willReturn($connection);
    $tasks->expects($this->once())
      ->method('t')
      ->willReturnArgument(0);

    $minimum_version = $tasks->minimumVersion();
    $name = $tasks->name();
@@ -146,7 +80,16 @@ public static function providerNameAndMinimumVersion(): array {
   * @legacy-covers ::name
   */
  public function testNameWithNoConnection(): void {
    $tasks = $this->createTasksNoConnection();
    $tasks = $this->getMockBuilder(Tasks::class)
      ->onlyMethods(['t', 'isConnectionActive'])
      ->getMock();
    $tasks->expects($this->once())
      ->method('isConnectionActive')
      ->willReturn(FALSE);
    $tasks->expects($this->once())
      ->method('t')
      ->willReturnArgument(0);

    $this->assertSame('MySQL, MariaDB, or equivalent', $tasks->name());
  }