9 use Magento\Setup\Validator\DbValidator;
23 private $connectionFactory;
32 $this->connectionFactory = $this->createMock(\
Magento\Setup\
Module\ConnectionFactory::class);
33 $this->connection = $this->getMockForAbstractClass(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
34 $this->connectionFactory->expects($this->any())->method(
'create')->willReturn($this->connection);
35 $this->dbValidator =
new DbValidator($this->connectionFactory);
41 ->expects($this->exactly(2))
43 ->with(
'SELECT version()')
44 ->willReturn(
'5.6.0-0ubuntu0.12.04.1');
45 $pdo = $this->getMockForAbstractClass(\Zend_Db_Statement_Interface::class, [],
'',
false);
47 ->expects($this->atLeastOnce())
60 [
'CREATE TEMPORARY TABLES'],
69 $accessibleDbs = [
'some_db',
'name',
'another_db'];
71 $pdo->expects($this->atLeastOnce())
75 [\PDO::FETCH_COLUMN, 0, $accessibleDbs],
76 [\PDO::FETCH_NUM,
null, $listOfPrivileges]
79 $this->assertEquals(
true, $this->dbValidator->checkDatabaseConnection(
'name',
'host',
'user',
'password'));
80 $this->assertEquals(
true, $this->dbValidator->checkDatabaseConnection(
'name',
'host:3339',
'user',
'password'));
90 ->expects($this->once())
92 ->with(
'SELECT version()')
93 ->willReturn(
'5.6.0-0ubuntu0.12.04.1');
94 $pdo = $this->getMockForAbstractClass(\Zend_Db_Statement_Interface::class, [],
'',
false);
96 ->expects($this->atLeastOnce())
99 $listOfPrivileges = [[
'SELECT']];
100 $accessibleDbs = [
'some_db',
'name',
'another_db'];
102 $pdo->expects($this->atLeastOnce())
106 [\PDO::FETCH_COLUMN, 0, $accessibleDbs],
107 [\PDO::FETCH_NUM,
null, $listOfPrivileges]
110 $this->dbValidator->checkDatabaseConnection(
'name',
'host',
'user',
'password');
120 ->expects($this->once())
122 ->with(
'SELECT version()')
123 ->willReturn(
'5.6.0-0ubuntu0.12.04.1');
124 $pdo = $this->getMockForAbstractClass(\Zend_Db_Statement_Interface::class, [],
'',
false);
126 ->expects($this->atLeastOnce())
129 $accessibleDbs = [
'some_db',
'another_db'];
131 $pdo->expects($this->atLeastOnce())
133 ->willReturn($accessibleDbs);
134 $this->dbValidator->checkDatabaseConnection(
'name',
'host',
'user',
'password');
139 $this->assertEquals(
true, $this->dbValidator->checkDatabaseTablePrefix(
'test'));
148 $this->assertEquals(
true, $this->dbValidator->checkDatabaseTablePrefix(
'_wrong_format'));
159 $this->dbValidator->checkDatabaseTablePrefix(
'mvbXzXzItSIr0wrZW3gqgV2UKrWiK1Mj7bkBlW72rZW3gqgV2UKrWiK1M')
169 $connectionFactory = $this->createMock(\
Magento\Setup\
Module\ConnectionFactory::class);
170 $connectionFactory->expects($this->once())->method(
'create')->willReturn(
false);
171 $this->dbValidator =
new DbValidator($connectionFactory);
172 $this->dbValidator->checkDatabaseConnection(
'name',
'host',
'user',
'password');
182 ->expects($this->once())
184 ->with(
'SELECT version()')
185 ->willReturn(
'5.5.40-0ubuntu0.12.04.1');
186 $this->dbValidator->checkDatabaseConnection(
'name',
'host',
'user',
'password');
testCheckDatabaseTablePrefixWrongFormat()
testCheckDatabaseConnectionFailed()
testCheckDatabaseTablePrefixWrongLength()
testCheckDatabaseConnectionNotEnoughPrivileges()
testCheckDatabaseConnectionDbNotAccessible()
testCheckDatabaseTablePrefix()
testCheckDatabaseConnection()
testCheckDatabaseConnectionIncompatible()