Skip to content

Commit

Permalink
Missing port parameter added to MysqldumpCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
lzakrzewski committed May 15, 2016
1 parent 6a1115f commit dfe6f80
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/BackupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 11 additions & 1 deletion src/Command/MysqldumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand All @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/BackupFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 16 additions & 5 deletions tests/Command/MysqldumpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,38 @@ 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()
);
}

/** @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');

Expand All @@ -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');

Expand Down

0 comments on commit dfe6f80

Please sign in to comment.