Skip to content

Commit c0bee55

Browse files
Merge branch 'MAGETWO-52981' of https://github.com/magento-tango/magento2ce into MAGETWO-55147
2 parents 51a147b + 9ac0e62 commit c0bee55

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

dev/tests/integration/framework/Magento/TestFramework/Db/Mysql.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
class Mysql extends \Magento\TestFramework\Db\AbstractDb
1515
{
16+
/**
17+
* Default port
18+
*/
19+
const DEFAULT_PORT = 3306;
20+
1621
/**
1722
* Defaults extra file name
1823
*/
@@ -32,12 +37,25 @@ class Mysql extends \Magento\TestFramework\Db\AbstractDb
3237
*/
3338
private $_defaultsExtraFile;
3439

40+
/**
41+
* Port number for connection
42+
*
43+
* @var integer
44+
*/
45+
private $_port;
46+
3547
/**
3648
* {@inheritdoc}
3749
*/
3850
public function __construct($host, $user, $password, $schema, $varPath, \Magento\Framework\Shell $shell)
3951
{
4052
parent::__construct($host, $user, $password, $schema, $varPath, $shell);
53+
$this->_port = self::DEFAULT_PORT;
54+
if (strpos($this->_host, ':') !== false) {
55+
list($host, $port) = explode(':', $this->_host);
56+
$this->_host = $host;
57+
$this->_port = (int) $port;
58+
}
4159
$this->_dbDumpFile = $this->_varPath . '/setup_dump_' . $this->_schema . '.sql';
4260
$this->_defaultsExtraFile = rtrim($this->_varPath, '\\/') . '/' . self::DEFAULTS_EXTRA_FILE_NAME;
4361
}
@@ -49,10 +67,11 @@ public function cleanup()
4967
{
5068
$this->ensureDefaultsExtraFile();
5169
$this->_shell->execute(
52-
'mysql --defaults-file=%s --host=%s %s -e %s',
70+
'mysql --defaults-file=%s --host=%s --port=%s %s -e %s',
5371
[
5472
$this->_defaultsExtraFile,
5573
$this->_host,
74+
$this->_port,
5675
$this->_schema,
5776
"DROP DATABASE `{$this->_schema}`; CREATE DATABASE `{$this->_schema}`"
5877
]
@@ -86,8 +105,8 @@ public function storeDbDump()
86105
{
87106
$this->ensureDefaultsExtraFile();
88107
$this->_shell->execute(
89-
'mysqldump --defaults-file=%s --host=%s %s > %s',
90-
[$this->_defaultsExtraFile, $this->_host, $this->_schema, $this->getSetupDbDumpFilename()]
108+
'mysqldump --defaults-file=%s --host=%s --port=%s %s > %s',
109+
[$this->_defaultsExtraFile, $this->_host, $this->_port, $this->_schema, $this->getSetupDbDumpFilename()]
91110
);
92111
}
93112

@@ -102,8 +121,8 @@ public function restoreFromDbDump()
102121
throw new \LogicException("DB dump file does not exist: " . $this->getSetupDbDumpFilename());
103122
}
104123
$this->_shell->execute(
105-
'mysql --defaults-file=%s --host=%s %s < %s',
106-
[$this->_defaultsExtraFile, $this->_host, $this->_schema, $this->getSetupDbDumpFilename()]
124+
'mysql --defaults-file=%s --host=%s --port=%s %s < %s',
125+
[$this->_defaultsExtraFile, $this->_host, $this->_port, $this->_schema, $this->getSetupDbDumpFilename()]
107126
);
108127
}
109128

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ protected function _connect()
329329
throw new \Zend_Db_Adapter_Exception('No host configured to connect');
330330
}
331331

332+
if (isset($this->_config['port'])) {
333+
throw new \Zend_Db_Adapter_Exception('Port must be configured within host parameter (like localhost:3306');
334+
}
335+
336+
unset($this->_config['port']);
337+
332338
if (strpos($this->_config['host'], '/') !== false) {
333339
$this->_config['unix_socket'] = $this->_config['host'];
334340
unset($this->_config['host']);

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\Framework\DB\Adapter\AdapterInterface;
1515
use Magento\Framework\DB\Select;
1616
use Magento\Framework\DB\Select\SelectRenderer;
17+
use Magento\Framework\Model\ResourceModel\Type\Db\Pdo\Mysql;
18+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1719

1820
class MysqlTest extends \PHPUnit_Framework_TestCase
1921
{
@@ -523,4 +525,28 @@ public function getIndexNameDataProvider()
523525
['short_table_name', ['field1', 'field2'], '', 'SHORT_TABLE_NAME_FIELD1_FIELD2'],
524526
];
525527
}
528+
529+
public function testConfigValidation()
530+
{
531+
$subject = (new ObjectManager($this))->getObject(
532+
Mysql::class,
533+
[
534+
'config' => ['host' => 'localhost'],
535+
]
536+
);
537+
538+
$this->assertInstanceOf(Mysql::class, $subject);
539+
}
540+
541+
/**
542+
* @expectedException \InvalidArgumentException
543+
* @expectedExceptionMessage Port must be configured within host (like 'localhost:33390') parameter, not within port
544+
*/
545+
public function testConfigValidationByPortWithException()
546+
{
547+
(new ObjectManager($this))->getObject(
548+
Mysql::class,
549+
['config' => ['host' => 'localhost', 'port' => '33390']]
550+
);
551+
}
526552
}

lib/internal/Magento/Framework/Model/ResourceModel/Type/Db/Pdo/Mysql.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ private function getValidConfig(array $config)
114114
}
115115
}
116116

117+
if (isset($config['port'])) {
118+
throw new \InvalidArgumentException(
119+
"Port must be configured within host (like '$config[host]:$config[port]') parameter, not within port"
120+
);
121+
}
122+
117123
$config['active'] = !(
118124
$config['active'] === 'false'
119125
|| $config['active'] === false

setup/src/Magento/Setup/Test/Unit/Validator/DbValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp()
3838
public function testCheckDatabaseConnection()
3939
{
4040
$this->connection
41-
->expects($this->once())
41+
->expects($this->exactly(2))
4242
->method('fetchOne')
4343
->with('SELECT version()')
4444
->willReturn('5.6.0-0ubuntu0.12.04.1');
@@ -79,6 +79,7 @@ public function testCheckDatabaseConnection()
7979
]
8080
);
8181
$this->assertEquals(true, $this->dbValidator->checkDatabaseConnection('name', 'host', 'user', 'password'));
82+
$this->assertEquals(true, $this->dbValidator->checkDatabaseConnection('name', 'host:3339', 'user', 'password'));
8283
}
8384

8485
/**

0 commit comments

Comments
 (0)