Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for adding options after the db name #129

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
4 changes: 4 additions & 0 deletions src/Databases/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ public function getDumpCommand(string $dumpFile, string $temporaryCredentialsFil
$command[] = "--tables {$includeTables}";
}

foreach ($this->extraOptionsAfterDbName as $extraOptionAfterDbName) {
$command[] = $extraOptionAfterDbName;
}

return $this->echoToFile(implode(' ', $command), $dumpFile);
}

Expand Down
17 changes: 17 additions & 0 deletions src/DbDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ abstract class DbDumper
/** @var array */
protected $extraOptions = [];

/** @var array */
protected $extraOptionsAfterDbName = [];

/** @var object */
protected $compressor = null;

Expand Down Expand Up @@ -238,6 +241,20 @@ public function addExtraOption(string $extraOption)
return $this;
}

/**
* @param string $extraOptionAtEnd
*
* @return $this
*/
public function addExtraOptionAfterDbName(string $extraOptionAfterDbName)
{
if (! empty($extraOptionAfterDbName)) {
$this->extraOptionsAfterDbName[] = $extraOptionAfterDbName;
}

return $this;
}

abstract public function dumpToFile(string $dumpFile);

protected function checkIfDumpWasSuccessFul(Process $process, string $outputFile)
Expand Down
16 changes: 15 additions & 1 deletion tests/MySqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function it_can_generate_a_dump_command_without_using_comments()
}

/** @test */
public function it_can_generate_a_dump_command_without_using_extended_insterts()
public function it_can_generate_a_dump_command_without_using_extended_inserts()
{
$dumpCommand = MySql::create()
->setDbName('dbname')
Expand Down Expand Up @@ -302,6 +302,20 @@ public function it_can_add_extra_options()
$this->assertSame('\'mysqldump\' --defaults-extra-file="credentials.txt" --skip-comments --extended-insert --extra-option --another-extra-option="value" dbname > "dump.sql"', $dumpCommand);
}

/** @test */
public function it_can_add_extra_options_after_db_name()
{
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->addExtraOption('--extra-option')
->addExtraOptionAfterDbName('--another-extra-option="value"')
->getDumpCommand('dump.sql', 'credentials.txt');

$this->assertSame('\'mysqldump\' --defaults-extra-file="credentials.txt" --skip-comments --extended-insert --extra-option dbname --another-extra-option="value" > "dump.sql"', $dumpCommand);
}

/** @test */
public function it_can_get_the_host()
{
Expand Down