Skip to content

Commit

Permalink
Return command results.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle-S committed Mar 3, 2017
1 parent e50862d commit ea0254e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Commands/ClearOpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public function digipolisClearOpCache(
'host' => null,
]
) {
$this->taskClearOpCache($environment, $opts['host'])->run();
return $this->taskClearOpCache($environment, $opts['host'])->run();
}
}
2 changes: 1 addition & 1 deletion src/Commands/PartialCleanDirs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function digipolisCleanDir($dirs, $opts = ['sort' => PartialCleanDirsTask
}
$dirsArg[] = $dirParts[0];
}
$this->taskPartialCleanDirs($dirsArg)
return $this->taskPartialCleanDirs($dirsArg)
->sortBy($opts['sort'])
->run();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/PushPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function digipolisPushPackage(
$auth = $opts['key-file']
? new KeyFile($user, $opts['key-file'], $opts['password'])
: new Password($user, $opts['password']);
$this->taskPushPackage($host, $auth)
return $this->taskPushPackage($host, $auth)
->port($opts['port'])
->timeout($opts['timeout'])
->destinationFolder($destination)
Expand Down
11 changes: 6 additions & 5 deletions src/PartialCleanDirs.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ protected function cleanDir($dir, $keep)
$finder->sort($this->sort);
break;
}
foreach ($finder as $item) {
if ($keep) {
$keep--;
continue;
}
$items = iterator_to_array($finder->getIterator());
if ($keep) {
array_splice($items, -$keep);
}
foreach ($items as $item) {
$this->fs->chmod($item, 0777, 0000, true);
$this->fs->remove($item);
}
}
Expand Down
95 changes: 70 additions & 25 deletions tests/PartialCleanDirsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,54 +75,99 @@ public function testRun() {
->getMock();

$fs->expects($this->at(0))
->method('remove')
->with('dir6');
->method('chmod')
->with('dir1', 0777, 0000, true);
$fs->expects($this->at(1))
->method('remove')
->with('dir7');
->with('dir1');
$fs->expects($this->at(2))
->method('remove')
->with('dir8');
->method('chmod')
->with('dir2', 0777, 0000, true);
$fs->expects($this->at(3))
->method('remove')
->with('dir9');
->with('dir2');
$fs->expects($this->at(4))
->method('remove')
->with('dir10');
->method('chmod')
->with('dir3', 0777, 0000, true);
$fs->expects($this->at(5))
->method('remove')
->with('dir11');

// Delete items in path/to/dir2.
->with('dir3');
$fs->expects($this->at(6))
->method('remove')
->with('dir4');
->method('chmod')
->with('dir4', 0777, 0000, true);
$fs->expects($this->at(7))
->method('remove')
->with('dir5');
->with('dir4');
$fs->expects($this->at(8))
->method('remove')
->with('dir6');
->method('chmod')
->with('dir5', 0777, 0000, true);
$fs->expects($this->at(9))
->method('remove')
->with('dir7');
->with('dir5');
$fs->expects($this->at(10))
->method('remove')
->with('dir8');
->method('chmod')
->with('dir6', 0777, 0000, true);
$fs->expects($this->at(11))
->method('remove')
->with('dir9');
->with('dir6');

// Delete items in path/to/dir2.
$fs->expects($this->at(12))
->method('remove')
->with('dir10');
->method('chmod')
->with('dir1', 0777, 0000, true);
$fs->expects($this->at(13))
->method('remove')
->with('dir11');
->with('dir1');
$fs->expects($this->at(14))
->method('chmod')
->with('dir2', 0777, 0000, true);
$fs->expects($this->at(15))
->method('remove')
->with('dir2');
$fs->expects($this->at(16))
->method('chmod')
->with('dir3', 0777, 0000, true);
$fs->expects($this->at(17))
->method('remove')
->with('dir3');
$fs->expects($this->at(18))
->method('chmod')
->with('dir4', 0777, 0000, true);
$fs->expects($this->at(19))
->method('remove')
->with('dir4');
$fs->expects($this->at(20))
->method('chmod')
->with('dir5', 0777, 0000, true);
$fs->expects($this->at(21))
->method('remove')
->with('dir5');
$fs->expects($this->at(22))
->method('chmod')
->with('dir6', 0777, 0000, true);
$fs->expects($this->at(23))
->method('remove')
->with('dir6');
$fs->expects($this->at(24))
->method('chmod')
->with('dir7', 0777, 0000, true);
$fs->expects($this->at(25))
->method('remove')
->with('dir7');
$fs->expects($this->at(26))
->method('chmod')
->with('dir8', 0777, 0000, true);
$fs->expects($this->at(27))
->method('remove')
->with('dir8');

// Delete items in path/to/dir3.
$fs->expects($this->at(14))
$fs->expects($this->at(28))
->method('chmod')
->with('dir1', 0777, 0000, true);
$fs->expects($this->at(29))
->method('remove')
->with('dir11');
->with('dir1');

$result = $this->taskPartialCleanDirs($dirs, $finder, $fs)
->run();
Expand Down

0 comments on commit ea0254e

Please sign in to comment.