Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianfeldmann committed Aug 12, 2023
1 parent 48f98cc commit b15ff6b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 49 deletions.
62 changes: 25 additions & 37 deletions src/Cli/Executable/Mongodump.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __construct(string $path = '')
* Set path to dump to.
*
* @param string $path
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function dumpToDirectory(string $path) : Mongodump
{
Expand All @@ -135,7 +135,7 @@ public function dumpToDirectory(string $path) : Mongodump
* Use ipv6 to connect.
*
* @param boolean $bool
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function useIpv6(bool $bool) : Mongodump
{
Expand All @@ -147,7 +147,7 @@ public function useIpv6(bool $bool) : Mongodump
* Set uri to dump from
*
* @param string $uri
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function useUri(string $uri) : Mongodump
{
Expand All @@ -159,7 +159,7 @@ public function useUri(string $uri) : Mongodump
* Set host to dump from.
*
* @param string $host
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function useHost(string $host) : Mongodump
{
Expand All @@ -173,7 +173,7 @@ public function useHost(string $host) : Mongodump
* @param string $user
* @param string $password
* @param string $authDatabase
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function credentials(string $user = '', string $password = '', string $authDatabase = '') : Mongodump
{
Expand All @@ -187,7 +187,7 @@ public function credentials(string $user = '', string $password = '', string $au
* Dump only given databases.
*
* @param array $databases
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function dumpDatabases(array $databases) : Mongodump
{
Expand All @@ -199,7 +199,7 @@ public function dumpDatabases(array $databases) : Mongodump
* Dump only given collections.
*
* @param array $collections
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function dumpCollections(array $collections) : Mongodump
{
Expand All @@ -211,7 +211,7 @@ public function dumpCollections(array $collections) : Mongodump
* Exclude collections.
*
* @param array $collections
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function excludeCollections(array $collections) : Mongodump
{
Expand All @@ -223,7 +223,7 @@ public function excludeCollections(array $collections) : Mongodump
* Exclude collections with given prefixes.
*
* @param array $prefixes
* @return \phpbu\App\Cli\Executable\Mongodump
* @return Mongodump
*/
public function excludeCollectionsWithPrefix(array $prefixes) : Mongodump
{
Expand All @@ -234,8 +234,8 @@ public function excludeCollectionsWithPrefix(array $prefixes) : Mongodump
/**
* Mongodump CommandLine generator.
*
* @return \SebastianFeldmann\Cli\CommandLine
* @throws \phpbu\App\Exception
* @return CommandLine
* @throws Exception
*/
protected function createCommandLine() : CommandLine
{
Expand All @@ -246,38 +246,26 @@ protected function createCommandLine() : CommandLine
$cmd = new Cmd($this->binary);
$process->addCommand($cmd);

$cmd->addOption('--out', $this->dumpDir, ' ');
$cmd->addOption('--out', $this->dumpDir);
$cmd->addOptionIfNotEmpty('--ipv6', $this->useIPv6, false);
$cmd->addOptionIfNotEmpty('--uri', $this->uri, true, ' ');
$cmd->addOptionIfNotEmpty('--host', $this->host, true, ' ');
$cmd->addOptionIfNotEmpty('--username', $this->user, true, ' ');
$cmd->addOptionIfNotEmpty('--password', $this->password, true, ' ');
$cmd->addOptionIfNotEmpty('--authenticationDatabase', $this->authenticationDatabase, true, ' ');
$cmd->addOptionIfNotEmpty('--uri', $this->uri);
$cmd->addOptionIfNotEmpty('--host', $this->host);
$cmd->addOptionIfNotEmpty('--username', $this->user);
$cmd->addOptionIfNotEmpty('--password', $this->password);
$cmd->addOptionIfNotEmpty('--authenticationDatabase', $this->authenticationDatabase);

if (count($this->databases)) {
foreach ($this->databases as $db) {
$cmd->addOption('--db', $db, ' ');
}
foreach ($this->databases as $db) {
$cmd->addOption('--db', $db);
}

if (count($this->collections)) {
foreach ($this->collections as $col) {
$cmd->addOption('--collection', $col, ' ');
}
foreach ($this->collections as $col) {
$cmd->addOption('--collection', $col);
}

if (count($this->excludeCollections)) {
foreach ($this->excludeCollections as $col) {
$cmd->addOption('--excludeCollection', $col, ' ');
}
foreach ($this->excludeCollections as $col) {
$cmd->addOption('--excludeCollection', $col);
}

if (count($this->excludeCollectionsWithPrefix)) {
foreach ($this->excludeCollectionsWithPrefix as $col) {
$cmd->addOption('--excludeCollectionWithPrefix', $col, ' ');
}
foreach ($this->excludeCollectionsWithPrefix as $col) {
$cmd->addOption('--excludeCollectionWithPrefix', $col);
}
$cmd->addOptionIfNotEmpty('--excludeCollectionWithPrefix', $this->excludeCollectionsWithPrefix);

return $process;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/phpbu/Backup/Source/MongodumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function testDefault()

$executable = $mongodump->getExecutable($target);

$this->assertEquals('"' . PHPBU_TEST_BIN . '/mongodump" --out \'' . __DIR__ . '/dump\'', $executable->getCommand());
$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'' . __DIR__ . '/dump\'',
$executable->getCommand()
);
}

/**
Expand Down
24 changes: 13 additions & 11 deletions tests/phpbu/Cli/Executable/MongodumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testDefault()
$mongo->dumpToDirectory('./dump');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\'',
$mongo->getCommand()
);
}
Expand All @@ -49,7 +49,7 @@ public function testUser()
$mongo->dumpToDirectory('./dump')->credentials('root');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --username \'root\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --username=\'root\'',
$mongo->getCommand()
);
}
Expand All @@ -63,7 +63,7 @@ public function testPassword()
$mongo->dumpToDirectory('./dump')->credentials('', 'secret');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --password \'secret\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --password=\'secret\'',
$mongo->getCommand()
);
}
Expand All @@ -77,7 +77,7 @@ public function testHost()
$mongo->dumpToDirectory('./dump')->useHost('example.com');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --host \'example.com\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --host=\'example.com\'',
$mongo->getCommand()
);
}
Expand All @@ -91,7 +91,7 @@ public function testDatabases()
$mongo->dumpToDirectory('./dump')->dumpDatabases(['db1', 'db2']);

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --db \'db1\' --db \'db2\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --db=\'db1\' --db=\'db2\'',
$mongo->getCommand()
);
}
Expand All @@ -105,8 +105,8 @@ public function testCollections()
$mongo->dumpToDirectory('./dump')->dumpCollections(['collection1', 'collection2']);

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump'
. '\' --collection \'collection1\' --collection \'collection2\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump'
. '\' --collection=\'collection1\' --collection=\'collection2\'',
$mongo->getCommand()
);
}
Expand All @@ -120,7 +120,7 @@ public function testIPv6()
$mongo->dumpToDirectory('./dump')->useIpv6(true);

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --ipv6',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --ipv6',
$mongo->getCommand()
);
}
Expand All @@ -134,7 +134,8 @@ public function testExcludeCollections()
$mongo->dumpToDirectory('./dump')->excludeCollections(['col1', 'col2']);

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --excludeCollection \'col1\' \'col2\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' .
'\' --excludeCollection=\'col1\' --excludeCollection=\'col2\'',
$mongo->getCommand()
);
}
Expand All @@ -148,7 +149,8 @@ public function testExcludeCollectionsWithPrefix()
$mongo->dumpToDirectory('./dump')->excludeCollectionsWithPrefix(['pre1', 'pre2']);

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --excludeCollectionWithPrefix \'pre1\' \'pre2\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' .
'\' --excludeCollectionWithPrefix=\'pre1\' --excludeCollectionWithPrefix=\'pre2\'',
$mongo->getCommand()
);
}
Expand All @@ -162,7 +164,7 @@ public function testUri()
$mongo->dumpToDirectory('./dump')->useUri('mymongouri');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --uri \'mymongouri\'',
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --uri=\'mymongouri\'',
$mongo->getCommand()
);
}
Expand Down

0 comments on commit b15ff6b

Please sign in to comment.