From dfe6f80cdb4398e4d6b5999bfaf111a32601c637 Mon Sep 17 00:00:00 2001 From: lzakrzewski Date: Sun, 15 May 2016 15:42:53 +0200 Subject: [PATCH] Missing port parameter added to MysqldumpCommand --- src/BackupFactory.php | 3 ++- src/Command/MysqldumpCommand.php | 12 +++++++++++- tests/BackupFactoryTest.php | 2 +- tests/Command/MysqldumpCommandTest.php | 21 ++++++++++++++++----- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/BackupFactory.php b/src/BackupFactory.php index 7f23275..000e597 100644 --- a/src/BackupFactory.php +++ b/src/BackupFactory.php @@ -48,11 +48,12 @@ private static function mySqlBackup(EntityManager $entityManager) } $host = (isset($params['host'])) ? $params['host'] : null; + $port = (isset($params['port'])) ? $params['port'] : null; $user = (isset($params['user'])) ? $params['user'] : null; $password = (isset($params['password'])) ? $params['password'] : null; $purger = PurgerFactory::instance($entityManager); - $command = new MysqldumpCommand($params['dbname'], $host, $user, $password); + $command = new MysqldumpCommand($params['dbname'], $host, $port, $user, $password); return new MySqlBackup($entityManager->getConnection(), InMemoryStorage::instance(), $purger, $command); } diff --git a/src/Command/MysqldumpCommand.php b/src/Command/MysqldumpCommand.php index d0bc6bf..4b1f37d 100644 --- a/src/Command/MysqldumpCommand.php +++ b/src/Command/MysqldumpCommand.php @@ -10,6 +10,8 @@ class MysqldumpCommand implements Command private $dbname; /** @var string */ private $host; + /** @var null|string */ + private $port; /** @var string */ private $user; /** @var string */ @@ -18,13 +20,15 @@ class MysqldumpCommand implements Command /** * @param $dbname * @param string|null $host + * @param string|null $port * @param string|null $user * @param string|null $password */ - public function __construct($dbname, $host = null, $user = null, $password = null) + public function __construct($dbname, $host = null, $port = null, $user = null, $password = null) { $this->dbname = $dbname; $this->host = $host; + $this->port = $port; $this->user = $user; $this->password = $password; } @@ -37,9 +41,15 @@ public function run() if (null !== $this->host && strlen($this->host)) { $command .= sprintf(' --host=%s', escapeshellarg($this->host)); } + + if (null !== $this->port && strlen($this->port)) { + $command .= sprintf(' --port=%s', escapeshellarg($this->port)); + } + if (null !== $this->user && strlen($this->user)) { $command .= sprintf(' --user=%s', escapeshellarg($this->user)); } + if (null !== $this->password && strlen($this->password)) { $command .= sprintf(' --password=%s', escapeshellarg($this->password)); } diff --git a/tests/BackupFactoryTest.php b/tests/BackupFactoryTest.php index e9e1ac5..4c7d9b5 100644 --- a/tests/BackupFactoryTest.php +++ b/tests/BackupFactoryTest.php @@ -96,7 +96,7 @@ private function givenMySqlDatabasePlatformWasEnabled() $mySqlPlatform = $this->prophesize('\Doctrine\DBAL\Platforms\MySqlPlatform'); $this->connection->getDatabasePlatform()->willReturn($mySqlPlatform->reveal()); - $this->connection->getParams()->willReturn(['dbname' => 'test', 'host' => 'localhost', 'user' => 'johndoe', 'password' => 'testing1']); + $this->connection->getParams()->willReturn(['dbname' => 'test', 'host' => 'localhost', 'port' => '3306', 'user' => 'johndoe', 'password' => 'testing1']); } private function givenUnsupportedDatabasePlatformWasEnabled() diff --git a/tests/Command/MysqldumpCommandTest.php b/tests/Command/MysqldumpCommandTest.php index 75b6e3f..49b4e25 100644 --- a/tests/Command/MysqldumpCommandTest.php +++ b/tests/Command/MysqldumpCommandTest.php @@ -7,10 +7,10 @@ class MysqldumpCommandTest extends \PHPUnit_Framework_TestCase /** @test */ public function it_can_call_full_command_to_dump_database() { - $command = new MysqldumpDummyCommand('dbname', 'host', 'user', 'password'); + $command = new MysqldumpDummyCommand('dbname', 'host', '3306', 'user', 'password'); $this->assertEquals( - "mysqldump 'dbname' --no-create-info --host='host' --user='user' --password='password'", + "mysqldump 'dbname' --no-create-info --host='host' --port='3306' --user='user' --password='password'", $command->run() ); } @@ -18,16 +18,27 @@ public function it_can_call_full_command_to_dump_database() /** @test */ public function it_can_call_command_to_dump_database_without_password() { - $command = new MysqldumpDummyCommand('dbname', 'host', 'user'); + $command = new MysqldumpDummyCommand('dbname', 'host', '3306', 'user'); $this->assertEquals( - "mysqldump 'dbname' --no-create-info --host='host' --user='user'", + "mysqldump 'dbname' --no-create-info --host='host' --port='3306' --user='user'", $command->run() ); } /** @test */ public function it_can_call_command_to_dump_database_without_password_and_user() + { + $command = new MysqldumpDummyCommand('dbname', 'host', '3306'); + + $this->assertEquals( + "mysqldump 'dbname' --no-create-info --host='host' --port='3306'", + $command->run() + ); + } + + /** @test */ + public function it_can_call_command_to_dump_database_without_password_and_user_and_port() { $command = new MysqldumpDummyCommand('dbname', 'host'); @@ -38,7 +49,7 @@ public function it_can_call_command_to_dump_database_without_password_and_user() } /** @test */ - public function it_can_call_command_to_dump_database_without_password_user_and_host() + public function it_can_call_command_to_dump_database_without_password_user_and_host_and_port() { $command = new MysqldumpDummyCommand('dbname');