thephpleague / climate

PHP's best friend for the terminal.
http://climate.thephpleague.com
MIT License
1.87k stars 126 forks source link

Progress precision #198

Closed quasipickle closed 3 days ago

quasipickle commented 1 year ago

For long running progress bars, seeing it sit at 1% isn't exciting, so I added the ability to change the precision of the percentage.

Usage is straightforward:

$progress = $this->cli->progress(3);
$progress->precision(3);
$progress->current(1);
===>         33.333%

I tried to write a test, but I'm not well versed in unit-testing so this causes an error I'm not sure how to fix:

vendor/bin/phpunit --filter it_can_output_a_progress_bar_with_precision tests/ProgressTest.php
PHPUnit 9.5.27 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 00:00.015, Memory: 6.00 MB

There was 1 error:

=======================>                                                33.3%'). Either the method was unexpected or its arguments matched no expected argument list for this method
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_2_League_CLImate_Util_Output::write('

/var/www/html/climate/vendor/mockery/mockery/library/Mockery/ExpectationDirector.php:92
/var/www/html/climate/src/TerminalObject/Dynamic/Progress.php:198
/var/www/html/climate/src/TerminalObject/Dynamic/Progress.php:125
/var/www/html/climate/tests/ProgressTest.php:104

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
duncan3dc commented 3 days ago

Hi @quasipickle sorry for the delay here!

Yes some of the testing helpers are very painful to work with, I've added a couple of tests for you and merged as 70a0e1b796b9b2ab4f47e3092538a5b878f7ee48 now, thank you!