Permalink
Browse files

[Console] [ProgressHelper] better percentage precision

  • Loading branch information...
1 parent 3eeaa72 commit a3f26e849db2c38922cf835e9705701706c4a6ef @pborreli pborreli committed Oct 12, 2012
Showing with 13 additions and 1 deletion.
  1. +1 −1 Helper/ProgressHelper.php
  2. +12 −0 Tests/Helper/ProgressHelperTest.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'])) {
@@ -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));

0 comments on commit a3f26e8

Please sign in to comment.