Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Nov 12, 2021
1 parent 44bccf4 commit 88f9195
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
36 changes: 18 additions & 18 deletions tests/Cli/CliProgressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testMinimal()
$output = Helper::executeReal('test:progress', ['case' => 'minimal', 'sleep' => 1]);
isSame(0, $output[0]);
isSame('', $output[1]);
isContain('Progress of minimal', $output[2]);
isNotContain('Progress of minimal', $output[2]);
isContain('0% (0 / 2) [>', $output[2]);
isContain('50% (1 / 2) [•', $output[2]);
isContain('100% (2 / 2) [•', $output[2]);
Expand All @@ -46,8 +46,13 @@ public function testMinimal()

public function testMinimalVirtual()
{
$output = Helper::executeVirtaul('test:progress', ['case' => 'minimal']);
isContain('Progress of minimal', $output);
$output = Helper::executeVirtaul('test:progress', ['case' => 'one-message']);
isContain('Progress of one-message', $output);
isContain('Last Step Message: 1, 1, 1', $output);

$output = Helper::executeVirtaul('test:progress', ['case' => 'array-assoc']);
isContain('Progress of array-assoc', $output);
isContain('Last Step Message: value_2, key_2, 1', $output);
}

public function testNoItems()
Expand Down Expand Up @@ -152,6 +157,16 @@ public function testProgressMessages()
' * (0): 0',
' * (1): Progress stopped',
]), $stdOut);


[$exitCode, $stdOut, $errOut] = $this->exec('output-as-array');
isSame('', $errOut);
isSame(0, $exitCode);
isSame(implode("\n", [
'Working on "output-as-array". Number of steps: 2.',
' * (key_1/0): value_1; key_1; 0',
' * (key_2/1): value_2; key_2; 1',
]), $stdOut);
}

public function testException()
Expand Down Expand Up @@ -268,19 +283,4 @@ private function exec(string $testCase, array $addOptions = [], bool $noProgress

return Helper::executeReal('test:progress', $options);
}

/**
* @param string $testCase
* @param array $addOptions
* @param bool $noProgress
* @return string
*/
private function execVirtual(string $testCase, array $addOptions = [], bool $noProgress = true): string
{
$options['no-progress'] = null;
$options['case'] = $testCase;
$options = array_merge($options, $addOptions);

return Helper::executeVirtaul('test:progress', $options);
}
}
9 changes: 8 additions & 1 deletion tests/fake-app/Commands/TestProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function executeAction(): int
if ($testCase === 'minimal') {
ProgressBar::run(2, function () {
sleep($this->getOptInt('sleep'));
}, $testCase);
});
}

if ($testCase === 'no-messages') {
Expand All @@ -90,6 +90,13 @@ protected function executeAction(): int
}, $testCase);
}

if ($testCase === 'output-as-array') {
$list = ['key_1' => 'value_1', 'key_2' => 'value_2'];
ProgressBar::run($list, function ($stepValue, $stepIndex, $currentStep) {
return [$stepValue, $stepIndex, $currentStep];
}, $testCase);
}

if ($testCase === 'array-int') {
ProgressBar::run([4, 5, 6], function ($stepValue, $stepIndex, $currentStep) {
return "{$stepValue}, {$stepIndex}, {$currentStep}";
Expand Down

0 comments on commit 88f9195

Please sign in to comment.