Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Console] [ProgressHelper] better percentage precision

  • Loading branch information...
commit a3f26e849db2c38922cf835e9705701706c4a6ef 1 parent 3eeaa72
@pborreli pborreli authored
Showing with 13 additions and 1 deletion.
  1. +1 −1  Helper/ProgressHelper.php
  2. +12 −0 Tests/Helper/ProgressHelperTest.php
View
2  Helper/ProgressHelper.php
@@ -304,7 +304,7 @@ private function generate($finish = false)
$vars = array();
$percent = 0;
if ($this->max > 0) {
- $percent = (double) round($this->current / $this->max, 1);
+ $percent = (double) round($this->current / $this->max, 2);
}
if (isset($this->formatVars['bar'])) {
View
12 Tests/Helper/ProgressHelperTest.php
@@ -63,6 +63,18 @@ public function testCustomizations()
$this->assertEquals($this->generateOutput(' 1/10 [_/ ] 10%'), stream_get_contents($output->getStream()));
}
+ public function testPercent()
+ {
+ $progress = new ProgressHelper();
+ $progress->start($output = $this->getOutputStream(), 50);
+ $progress->display();
+ $progress->advance();
+ $progress->advance();
+
+ rewind($output->getStream());
+ $this->assertEquals($this->generateOutput(' 0/50 [>---------------------------] 0%').$this->generateOutput(' 1/50 [>---------------------------] 2%').$this->generateOutput(' 2/50 [=>--------------------------] 4%'), stream_get_contents($output->getStream()));
+ }
+
protected function getOutputStream()
{
return new StreamOutput(fopen('php://memory', 'r+', false));
Please sign in to comment.
Something went wrong with that request. Please try again.