Skip to content

Commit b15ff6b

Browse files
Fix unit tests
1 parent 48f98cc commit b15ff6b

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

src/Cli/Executable/Mongodump.php

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function __construct(string $path = '')
123123
* Set path to dump to.
124124
*
125125
* @param string $path
126-
* @return \phpbu\App\Cli\Executable\Mongodump
126+
* @return Mongodump
127127
*/
128128
public function dumpToDirectory(string $path) : Mongodump
129129
{
@@ -135,7 +135,7 @@ public function dumpToDirectory(string $path) : Mongodump
135135
* Use ipv6 to connect.
136136
*
137137
* @param boolean $bool
138-
* @return \phpbu\App\Cli\Executable\Mongodump
138+
* @return Mongodump
139139
*/
140140
public function useIpv6(bool $bool) : Mongodump
141141
{
@@ -147,7 +147,7 @@ public function useIpv6(bool $bool) : Mongodump
147147
* Set uri to dump from
148148
*
149149
* @param string $uri
150-
* @return \phpbu\App\Cli\Executable\Mongodump
150+
* @return Mongodump
151151
*/
152152
public function useUri(string $uri) : Mongodump
153153
{
@@ -159,7 +159,7 @@ public function useUri(string $uri) : Mongodump
159159
* Set host to dump from.
160160
*
161161
* @param string $host
162-
* @return \phpbu\App\Cli\Executable\Mongodump
162+
* @return Mongodump
163163
*/
164164
public function useHost(string $host) : Mongodump
165165
{
@@ -173,7 +173,7 @@ public function useHost(string $host) : Mongodump
173173
* @param string $user
174174
* @param string $password
175175
* @param string $authDatabase
176-
* @return \phpbu\App\Cli\Executable\Mongodump
176+
* @return Mongodump
177177
*/
178178
public function credentials(string $user = '', string $password = '', string $authDatabase = '') : Mongodump
179179
{
@@ -187,7 +187,7 @@ public function credentials(string $user = '', string $password = '', string $au
187187
* Dump only given databases.
188188
*
189189
* @param array $databases
190-
* @return \phpbu\App\Cli\Executable\Mongodump
190+
* @return Mongodump
191191
*/
192192
public function dumpDatabases(array $databases) : Mongodump
193193
{
@@ -199,7 +199,7 @@ public function dumpDatabases(array $databases) : Mongodump
199199
* Dump only given collections.
200200
*
201201
* @param array $collections
202-
* @return \phpbu\App\Cli\Executable\Mongodump
202+
* @return Mongodump
203203
*/
204204
public function dumpCollections(array $collections) : Mongodump
205205
{
@@ -211,7 +211,7 @@ public function dumpCollections(array $collections) : Mongodump
211211
* Exclude collections.
212212
*
213213
* @param array $collections
214-
* @return \phpbu\App\Cli\Executable\Mongodump
214+
* @return Mongodump
215215
*/
216216
public function excludeCollections(array $collections) : Mongodump
217217
{
@@ -223,7 +223,7 @@ public function excludeCollections(array $collections) : Mongodump
223223
* Exclude collections with given prefixes.
224224
*
225225
* @param array $prefixes
226-
* @return \phpbu\App\Cli\Executable\Mongodump
226+
* @return Mongodump
227227
*/
228228
public function excludeCollectionsWithPrefix(array $prefixes) : Mongodump
229229
{
@@ -234,8 +234,8 @@ public function excludeCollectionsWithPrefix(array $prefixes) : Mongodump
234234
/**
235235
* Mongodump CommandLine generator.
236236
*
237-
* @return \SebastianFeldmann\Cli\CommandLine
238-
* @throws \phpbu\App\Exception
237+
* @return CommandLine
238+
* @throws Exception
239239
*/
240240
protected function createCommandLine() : CommandLine
241241
{
@@ -246,38 +246,26 @@ protected function createCommandLine() : CommandLine
246246
$cmd = new Cmd($this->binary);
247247
$process->addCommand($cmd);
248248

249-
$cmd->addOption('--out', $this->dumpDir, ' ');
249+
$cmd->addOption('--out', $this->dumpDir);
250250
$cmd->addOptionIfNotEmpty('--ipv6', $this->useIPv6, false);
251-
$cmd->addOptionIfNotEmpty('--uri', $this->uri, true, ' ');
252-
$cmd->addOptionIfNotEmpty('--host', $this->host, true, ' ');
253-
$cmd->addOptionIfNotEmpty('--username', $this->user, true, ' ');
254-
$cmd->addOptionIfNotEmpty('--password', $this->password, true, ' ');
255-
$cmd->addOptionIfNotEmpty('--authenticationDatabase', $this->authenticationDatabase, true, ' ');
251+
$cmd->addOptionIfNotEmpty('--uri', $this->uri);
252+
$cmd->addOptionIfNotEmpty('--host', $this->host);
253+
$cmd->addOptionIfNotEmpty('--username', $this->user);
254+
$cmd->addOptionIfNotEmpty('--password', $this->password);
255+
$cmd->addOptionIfNotEmpty('--authenticationDatabase', $this->authenticationDatabase);
256256

257-
if (count($this->databases)) {
258-
foreach ($this->databases as $db) {
259-
$cmd->addOption('--db', $db, ' ');
260-
}
257+
foreach ($this->databases as $db) {
258+
$cmd->addOption('--db', $db);
261259
}
262-
263-
if (count($this->collections)) {
264-
foreach ($this->collections as $col) {
265-
$cmd->addOption('--collection', $col, ' ');
266-
}
260+
foreach ($this->collections as $col) {
261+
$cmd->addOption('--collection', $col);
267262
}
268-
269-
if (count($this->excludeCollections)) {
270-
foreach ($this->excludeCollections as $col) {
271-
$cmd->addOption('--excludeCollection', $col, ' ');
272-
}
263+
foreach ($this->excludeCollections as $col) {
264+
$cmd->addOption('--excludeCollection', $col);
273265
}
274-
275-
if (count($this->excludeCollectionsWithPrefix)) {
276-
foreach ($this->excludeCollectionsWithPrefix as $col) {
277-
$cmd->addOption('--excludeCollectionWithPrefix', $col, ' ');
278-
}
266+
foreach ($this->excludeCollectionsWithPrefix as $col) {
267+
$cmd->addOption('--excludeCollectionWithPrefix', $col);
279268
}
280-
$cmd->addOptionIfNotEmpty('--excludeCollectionWithPrefix', $this->excludeCollectionsWithPrefix);
281269

282270
return $process;
283271
}

tests/phpbu/Backup/Source/MongodumpTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public function testDefault()
3232

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

35-
$this->assertEquals('"' . PHPBU_TEST_BIN . '/mongodump" --out \'' . __DIR__ . '/dump\'', $executable->getCommand());
35+
$this->assertEquals(
36+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'' . __DIR__ . '/dump\'',
37+
$executable->getCommand()
38+
);
3639
}
3740

3841
/**

tests/phpbu/Cli/Executable/MongodumpTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testDefault()
2525
$mongo->dumpToDirectory('./dump');
2626

2727
$this->assertEquals(
28-
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\'',
28+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\'',
2929
$mongo->getCommand()
3030
);
3131
}
@@ -49,7 +49,7 @@ public function testUser()
4949
$mongo->dumpToDirectory('./dump')->credentials('root');
5050

5151
$this->assertEquals(
52-
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --username \'root\'',
52+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --username=\'root\'',
5353
$mongo->getCommand()
5454
);
5555
}
@@ -63,7 +63,7 @@ public function testPassword()
6363
$mongo->dumpToDirectory('./dump')->credentials('', 'secret');
6464

6565
$this->assertEquals(
66-
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --password \'secret\'',
66+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --password=\'secret\'',
6767
$mongo->getCommand()
6868
);
6969
}
@@ -77,7 +77,7 @@ public function testHost()
7777
$mongo->dumpToDirectory('./dump')->useHost('example.com');
7878

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

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

107107
$this->assertEquals(
108-
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump'
109-
. '\' --collection \'collection1\' --collection \'collection2\'',
108+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump'
109+
. '\' --collection=\'collection1\' --collection=\'collection2\'',
110110
$mongo->getCommand()
111111
);
112112
}
@@ -120,7 +120,7 @@ public function testIPv6()
120120
$mongo->dumpToDirectory('./dump')->useIpv6(true);
121121

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

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

150151
$this->assertEquals(
151-
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --excludeCollectionWithPrefix \'pre1\' \'pre2\'',
152+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' .
153+
'\' --excludeCollectionWithPrefix=\'pre1\' --excludeCollectionWithPrefix=\'pre2\'',
152154
$mongo->getCommand()
153155
);
154156
}
@@ -162,7 +164,7 @@ public function testUri()
162164
$mongo->dumpToDirectory('./dump')->useUri('mymongouri');
163165

164166
$this->assertEquals(
165-
'"' . PHPBU_TEST_BIN . '/mongodump" --out \'./dump' . '\' --uri \'mymongouri\'',
167+
'"' . PHPBU_TEST_BIN . '/mongodump" --out=\'./dump' . '\' --uri=\'mymongouri\'',
166168
$mongo->getCommand()
167169
);
168170
}

0 commit comments

Comments
 (0)