class InstallTasksTest
Tests the MySQL install tasks.
Attributes
#[CoversClass(Tasks::class)]
#[Group('Database')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\mysql\Unit\InstallTasksTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of InstallTasksTest
File
-
core/
modules/ mysql/ tests/ src/ Unit/ InstallTasksTest.php, line 17
Namespace
Drupal\Tests\mysql\UnitView source
class InstallTasksTest extends UnitTestCase {
/**
* A connection object prophecy.
*
* @var \Drupal\mysql\Driver\Database\mysql\Connection|\Prophecy\Prophecy\ObjectProphecy
*/
private $connection;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->connection = $this->prophesize(Connection::class);
}
/**
* Creates a Tasks object for testing.
*
* @return \Drupal\mysql\Driver\Database\mysql\Install\Tasks
* A Tasks object.
*/
private function createTasks() : Tasks {
/** @var \Drupal\mysql\Driver\Database\mysql\Connection $connection */
$connection = $this->connection
->reveal();
return new class ($connection) extends Tasks {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
private $connection;
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
protected function isConnectionActive() {
return TRUE;
}
/**
* {@inheritdoc}
*/
protected function getConnection() {
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() {
return FALSE;
}
/**
* {@inheritdoc}
*/
protected function getConnection() {
return NULL;
}
/**
* {@inheritdoc}
*/
protected function t($string, array $args = [], array $options = []) {
return $string;
}
};
}
/**
* Tests name and minimum version.
*
* @legacy-covers ::minimumVersion
* @legacy-covers ::name
*/
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
* An array of test data.
*/
public static function providerNameAndMinimumVersion() : array {
return [
[
TRUE,
'MariaDB',
Tasks::MARIADB_MINIMUM_VERSION,
],
[
FALSE,
'MySQL, Percona Server, or equivalent',
Tasks::MYSQL_MINIMUM_VERSION,
],
];
}
/**
* Tests name with no connection.
*
* @legacy-covers ::name
*/
public function testNameWithNoConnection() : void {
$tasks = $this->createTasksNoConnection();
$this->assertSame('MySQL, MariaDB, Percona Server, or equivalent', $tasks->name());
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|
| ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
| ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
| 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 static | function | Provides test data. | |
| InstallTasksTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
| InstallTasksTest::testNameAndMinimumVersion | public | function | Tests name and minimum version. | |
| InstallTasksTest::testNameWithNoConnection | public | function | Tests name with no connection. | |
| 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. | |
| UnitTestCase::$root | protected | property | The app root. | |
| 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::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::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.