Skip to content

[Console][ProgressBar] redrawFrequency should never be 0 #16742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

dritter
Copy link
Contributor

@dritter dritter commented Nov 29, 2015

Set the redraw frequency at least to 1. Setting it to 0 would otherwise produce a "division by zero" error.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

why?

I had a piece of code that used a ProgressBar and set the redraw frequency to a calculated value. In some cases this calculated value was 0 (or just smaller than 1, internally a cast to int is made). In the setProgress the redraw frequency is used for a calculation of the period. There the error happens (and shows that redraw frequency should never be 0).

Ticket

There is no ticket concerning this issue. I could do one, if you want.

Tests

This gets tested implicitly in ProgressBarTest::testNonDecoratedOutputWithoutMax.

@TomasVotruba
Copy link
Contributor

Nice PR! Maybe I would add explicit test to cover the change in behavior of setRedrawFrequency() method.

@xabbuh xabbuh added the Console label Nov 29, 2015
@Tobion
Copy link
Contributor

Tobion commented Nov 29, 2015

👍 But please add a test

This gets tested implicitly in ProgressBarTest::testNonDecoratedOutputWithoutMax.

There cannot be a test for this. Otherwise it would fail.

@dritter dritter force-pushed the console_progressbar_redraw_freq_fix branch 3 times, most recently from ecdcaab to 368423b Compare November 30, 2015 17:38
@dritter
Copy link
Contributor Author

dritter commented Nov 30, 2015

Added tests and rebased against the newest 2.8 branch.

public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'),
array($output = $this->getOutputStream(), 6));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be on one line to be consistent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and $output is not used. please remove the var in testRedrawFrequency and testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven as well

@dritter dritter force-pushed the console_progressbar_redraw_freq_fix branch from 368423b to 6a0a811 Compare November 30, 2015 23:47
@dritter
Copy link
Contributor Author

dritter commented Dec 1, 2015

@Tobion All done. :)

@Tobion
Copy link
Contributor

Tobion commented Dec 1, 2015

👍 Should be merged in 2.7

Status: Reviewed

@stof
Copy link
Member

stof commented Dec 5, 2015

Thank you @dritter.

@stof stof closed this in 5549336 Dec 5, 2015
This was referenced Dec 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants