From 39d0bf433f8a1e4735681dfd32dc5e8a4554433c Mon Sep 17 00:00:00 2001 From: Everton da Rosa Date: Mon, 18 Nov 2024 05:47:03 -0300 Subject: [PATCH] feat: Adds methods in Progress to return the current value and total value of the progress bar. (#206) --- src/TerminalObject/Dynamic/Progress.php | 20 +++++++++++++++++++ tests/TerminalObject/Dynamic/ProgressTest.php | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/TerminalObject/Dynamic/Progress.php b/src/TerminalObject/Dynamic/Progress.php index a860b76..9fa19f6 100644 --- a/src/TerminalObject/Dynamic/Progress.php +++ b/src/TerminalObject/Dynamic/Progress.php @@ -338,4 +338,24 @@ protected function shouldRedraw($percentage, $label) { return ($this->force_redraw || $percentage != $this->current_percentage || $label != $this->label); } + + /** + * Gets de current progress value. + * + * @return integer The current progress value. + */ + public function getCurrent() + { + return $this->current; + } + + /** + * Gets the total value for the progress. + * + * @return integer The total progress value. + */ + public function getTotal() + { + return $this->total; + } } diff --git a/tests/TerminalObject/Dynamic/ProgressTest.php b/tests/TerminalObject/Dynamic/ProgressTest.php index a6e257e..cbebe41 100644 --- a/tests/TerminalObject/Dynamic/ProgressTest.php +++ b/tests/TerminalObject/Dynamic/ProgressTest.php @@ -402,4 +402,14 @@ public function testEach4() return $item; }); } + + public function testGetCurrent() + { + $this->assertEquals(0, $this->cli->progress(100)->getCurrent()); + } + + public function testGetTotal() + { + $this->assertEquals(100, $this->cli->progress(100)->getTotal()); + } }