Skip to content

Commit 02144f1

Browse files
Add 'protocol' option to mysqldump - issue #189
1 parent 34d9fb3 commit 02144f1

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/Backup/Source/Mysqldump.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class Mysqldump extends SimulatorExecutable implements Simulator
4343
*/
4444
private $port;
4545

46+
/**
47+
* Port to connect to
48+
* --protocol <TCP|SOCKET|PIPE|MEMORY>
49+
*
50+
* @var string
51+
*/
52+
private $protocol;
53+
4654
/**
4755
* User to connect with
4856
* --user <username>
@@ -183,6 +191,7 @@ public function setup(array $conf = [])
183191
$this->pathToMysqldump = Util\Arr::getValue($conf, 'pathToMysqldump', '');
184192
$this->host = Util\Arr::getValue($conf, 'host', '');
185193
$this->port = Util\Arr::getValue($conf, 'port', 0);
194+
$this->protocol = Util\Arr::getValue($conf, 'protocol', '');
186195
$this->user = Util\Arr::getValue($conf, 'user', '');
187196
$this->password = Util\Arr::getValue($conf, 'password', '');
188197
$this->gtidPurged = Util\Arr::getValue($conf, 'gtidPurged', '');
@@ -256,6 +265,7 @@ protected function createExecutable(Target $target) : Executable
256265
$executable->credentials($this->user, $this->password)
257266
->useHost($this->host)
258267
->usePort($this->port)
268+
->useProtocol($this->protocol)
259269
->useQuickMode($this->quick)
260270
->lockTables($this->lockTables)
261271
->dumpBlobsHexadecimal($this->hexBlob)

src/Cli/Executable/Mysqldump.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class Mysqldump extends Abstraction implements Executable
3939
*/
4040
private $port;
4141

42+
/**
43+
* The connection protocol
44+
* --protocol
45+
*
46+
* @var string
47+
*/
48+
private $protocol;
49+
4250
/**
4351
* User to connect with
4452
* --user <username>
@@ -227,6 +235,18 @@ public function usePort(int $port) : Mysqldump
227235
return $this;
228236
}
229237

238+
/**
239+
* Set the connection protocol.
240+
*
241+
* @param string $protocol
242+
* @return \phpbu\App\Cli\Executable\Mysqldump
243+
*/
244+
public function useProtocol(string $protocol) : Mysqldump
245+
{
246+
$this->protocol = $protocol;
247+
return $this;
248+
}
249+
230250
/**
231251
* Use '-q' quick mode.
232252
*
@@ -435,6 +455,7 @@ protected function createCommandLine() : CommandLine
435455
$cmd->addOptionIfNotEmpty('--password', $this->password);
436456
$cmd->addOptionIfNotEmpty('--host', $this->host);
437457
$cmd->addOptionIfNotEmpty('--port', $this->port);
458+
$cmd->addOptionIfNotEmpty('--protocol', $this->protocol);
438459
$cmd->addOptionIfNotEmpty('--lock-tables', $this->lockTables, false);
439460
$cmd->addOptionIfNotEmpty('--single-transaction', $this->singleTransaction, false);
440461
$cmd->addOptionIfNotEmpty('-q', $this->quick, false);

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ public function testPort()
9999
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --port=\'4711\' --all-databases', $executable->getCommand());
100100
}
101101

102+
/**
103+
* Tests Mysqldump::getExecutable
104+
*/
105+
public function testProtocol()
106+
{
107+
$target = $this->createTargetMock();
108+
$mysqldump = new Mysqldump();
109+
$mysqldump->setup(['pathToMysqldump' => PHPBU_TEST_BIN, 'protocol' => 'TCP']);
110+
111+
$executable = $mysqldump->getExecutable($target);
112+
113+
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --protocol=\'TCP\' --all-databases', $executable->getCommand());
114+
}
115+
102116
/**
103117
* Tests Mysqldump::getExecutable
104118
*/

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testDefault()
3030
/**
3131
* Tests Mysqldump::getCommandPrintable
3232
*/
33-
public function __testDefaultPrintable()
33+
public function testDefaultPrintable()
3434
{
3535
$mysqldump = new Mysqldump(PHPBU_TEST_BIN);
3636
$cmd = $mysqldump->getCommandPrintable();
@@ -139,6 +139,18 @@ public function testUsePort()
139139
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --port=\'1234\' --all-databases', $cmd);
140140
}
141141

142+
/**
143+
* Tests Mysqldump::useProtocol
144+
*/
145+
public function testUseProtocol()
146+
{
147+
$mysqldump = new Mysqldump(PHPBU_TEST_BIN);
148+
$mysqldump->useProtocol('TCP');
149+
$cmd = $mysqldump->getCommand();
150+
151+
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --protocol=\'TCP\' --all-databases', $cmd);
152+
}
153+
142154
/**
143155
* Tests Mysqldump::getCommand
144156
*/

0 commit comments

Comments
 (0)