class InstallTasksTest

Same name in other branches
  1. 10 core/modules/mysql/tests/src/Unit/InstallTasksTest.php \Drupal\Tests\mysql\Unit\InstallTasksTest
  2. 11.x core/modules/mysql/tests/src/Unit/InstallTasksTest.php \Drupal\Tests\mysql\Unit\InstallTasksTest

Tests the MySQL install tasks.

@coversDefaultClass \Drupal\mysql\Driver\Database\mysql\Install\Tasks @group Database

Hierarchy

Expanded class hierarchy of InstallTasksTest

File

core/modules/mysql/tests/src/Unit/InstallTasksTest.php, line 15

Namespace

Drupal\Tests\mysql\Unit
View source
class InstallTasksTest extends UnitTestCase {
    
    /**
     * A connection object prophecy.
     *
     * @var \Drupal\mysql\Driver\Database\mysql\Connection|\Prophecy\Prophecy\ObjectProphecy
     */
    private $connection;
    
    /**
     * {@inheritdoc}
     */
    public function setUp() : void {
        $this->connection = $this->prophesize(Connection::class);
    }
    
    /**
     * Creates a Tasks object for testing.
     *
     * @return \Drupal\mysql\Driver\Database\mysql\Install\Tasks
     */
    private function createTasks() : Tasks {
        
        /** @var \Drupal\mysql\Driver\Database\mysql\Connection $connection */
        $connection = $this->connection
            ->reveal();
        return new class ($connection) extends Tasks {
            private $connection;
            public function __construct(Connection $connection) {
                $this->connection = $connection;
            }
            protected function isConnectionActive() {
                return TRUE;
            }
            protected function getConnection() {
                return $this->connection;
            }
            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
     */
    private function createTasksNoConnection() : Tasks {
        return new class  extends Tasks {
            protected function isConnectionActive() {
                return FALSE;
            }
            protected function getConnection() {
                return NULL;
            }
            protected function t($string, array $args = [], array $options = []) {
                return $string;
            }

};
    }
    
    /**
     * @covers ::minimumVersion
     * @covers ::name
     * @dataProvider providerNameAndMinimumVersion
     */
    public function testNameAndMinimumVersion(bool $is_mariadb, string $expected_name, string $expected_minimum_version) : void {
        $this->connection
            ->isMariaDb()
            ->shouldBeCalledTimes(2)
            ->willReturn($is_mariadb);
        $tasks = $this->createTasks();
        $minimum_version = $tasks->minimumVersion();
        $name = $tasks->name();
        $this->assertSame($expected_minimum_version, $minimum_version);
        $this->assertSame($expected_name, $name);
    }
    
    /**
     * Provides test data.
     *
     * @return array
     */
    public function providerNameAndMinimumVersion() : array {
        return [
            [
                TRUE,
                'MariaDB',
                Tasks::MARIADB_MINIMUM_VERSION,
            ],
            [
                FALSE,
                'MySQL, Percona Server, or equivalent',
                Tasks::MYSQL_MINIMUM_VERSION,
            ],
        ];
    }
    
    /**
     * @covers ::name
     */
    public function testNameWithNoConnection() {
        $tasks = $this->createTasksNoConnection();
        $this->assertSame('MySQL, MariaDB, Percona Server, or equivalent', $tasks->name());
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
InstallTasksTest::$connection private property A connection object prophecy.
InstallTasksTest::createTasks private function Creates a Tasks object for testing.
InstallTasksTest::createTasksNoConnection private function Creates a Tasks object for testing, without connection.
InstallTasksTest::providerNameAndMinimumVersion public function Provides test data.
InstallTasksTest::setUp public function Overrides UnitTestCase::setUp
InstallTasksTest::testNameAndMinimumVersion public function @covers ::minimumVersion
@covers ::name
@dataProvider providerNameAndMinimumVersion
InstallTasksTest::testNameWithNoConnection public function @covers ::name
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.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUpBeforeClass public static function

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