From 32d643b8880d36d2d80cf27381944506e5ba51dd Mon Sep 17 00:00:00 2001 From: Everton da Rosa Date: Wed, 30 Oct 2024 13:35:49 -0300 Subject: [PATCH] feat: Adds methods in Progress to return the current value and total value of the progress bar. This commit adds methods in Progress to return the current value and total value of the progress bar. Issue #192 --- 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()); + } }