diff --git a/tests/Cli/CliProgressTest.php b/tests/Cli/CliProgressTest.php index eff6fea..4ec7a0d 100644 --- a/tests/Cli/CliProgressTest.php +++ b/tests/Cli/CliProgressTest.php @@ -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]); @@ -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() @@ -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() @@ -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); - } } diff --git a/tests/fake-app/Commands/TestProgress.php b/tests/fake-app/Commands/TestProgress.php index dd322d9..c998696 100644 --- a/tests/fake-app/Commands/TestProgress.php +++ b/tests/fake-app/Commands/TestProgress.php @@ -68,7 +68,7 @@ protected function executeAction(): int if ($testCase === 'minimal') { ProgressBar::run(2, function () { sleep($this->getOptInt('sleep')); - }, $testCase); + }); } if ($testCase === 'no-messages') { @@ -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}";