Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ protected function _connect()
throw new \Zend_Db_Adapter_Exception('No host configured to connect');
}

if (isset($this->_config['port'])) {
throw new \Zend_Db_Adapter_Exception('Port must be configured within host parameter');
}

unset($this->_config['port']);

if (strpos($this->_config['host'], '/') !== false) {
$this->_config['unix_socket'] = $this->_config['host'];
unset($this->_config['host']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\DB\Select\SelectRenderer;
use Magento\Framework\Model\ResourceModel\Type\Db\Pdo\Mysql;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class MysqlTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -523,4 +525,29 @@ public function getIndexNameDataProvider()
['short_table_name', ['field1', 'field2'], '', 'SHORT_TABLE_NAME_FIELD1_FIELD2'],
];
}

/**
* @test
*/
public function connectPortThrow()
{
$arguments = [
'config' => ['host' => 'localhost'],
];
$subject = (new ObjectManager($this))->getObject(Mysql::class, $arguments);
$this->assertInstanceOf(Mysql::class, $subject);

$arguments = [
'config' => ['host' => 'localhost', 'port' => '33390'],
];

try {
(new ObjectManager($this))->getObject(Mysql::class, $arguments);
$this->fail('an expected exception was not thrown');
} catch (\InvalidArgumentException $e) {
$expected = 'MySQL adapter: Port must be configured within host (like \'localhost:33390\') ' .
'parameter, not within port';
$this->assertSame($expected, $e->getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ private function getValidConfig(array $config)
}
}

if (isset($config['port'])) {
throw new \InvalidArgumentException(
"MySQL adapter: Port must be configured within host (like '$config[host]:$config[port]') parameter, " .
"not within port"
);
}

$config['active'] = !(
$config['active'] === 'false'
|| $config['active'] === false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUp()
public function testCheckDatabaseConnection()
{
$this->connection
->expects($this->once())
->expects($this->exactly(2))
->method('fetchOne')
->with('SELECT version()')
->willReturn('5.6.0-0ubuntu0.12.04.1');
Expand Down Expand Up @@ -79,6 +79,7 @@ public function testCheckDatabaseConnection()
]
);
$this->assertEquals(true, $this->dbValidator->checkDatabaseConnection('name', 'host', 'user', 'password'));
$this->assertEquals(true, $this->dbValidator->checkDatabaseConnection('name', 'host:3339', 'user', 'password'));
}

/**
Expand Down