Skip to content

Commit 21c4cc1

Browse files
Merge commit 'refs/pull/2735/head' of https://github.com/magento/magento2 into MAGETWO-52981
2 parents b844887 + b4e0901 commit 21c4cc1

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

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');
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: 27 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,29 @@ public function getIndexNameDataProvider()
523525
['short_table_name', ['field1', 'field2'], '', 'SHORT_TABLE_NAME_FIELD1_FIELD2'],
524526
];
525527
}
528+
529+
/**
530+
* @test
531+
*/
532+
public function connectPortThrow()
533+
{
534+
$arguments = [
535+
'config' => ['host' => 'localhost'],
536+
];
537+
$subject = (new ObjectManager($this))->getObject(Mysql::class, $arguments);
538+
$this->assertInstanceOf(Mysql::class, $subject);
539+
540+
$arguments = [
541+
'config' => ['host' => 'localhost', 'port' => '33390'],
542+
];
543+
544+
try {
545+
(new ObjectManager($this))->getObject(Mysql::class, $arguments);
546+
$this->fail('an expected exception was not thrown');
547+
} catch (\InvalidArgumentException $e) {
548+
$expected = 'MySQL adapter: Port must be configured within host (like \'localhost:33390\') ' .
549+
'parameter, not within port';
550+
$this->assertSame($expected, $e->getMessage());
551+
}
552+
}
526553
}

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

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

117+
if (isset($config['port'])) {
118+
throw new \InvalidArgumentException(
119+
"MySQL adapter: Port must be configured within host (like '$config[host]:$config[port]') parameter, " .
120+
"not within port"
121+
);
122+
}
123+
117124
$config['active'] = !(
118125
$config['active'] === 'false'
119126
|| $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)