From c6adc8741122b15cf134b2cac54768dd637f5f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 28 Jul 2022 10:13:03 +0200 Subject: [PATCH] Do not pass `null` to the `$text` parameter of adapter's `notify()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `$text` parameter is documented to take a `string`, not a `?string` and in fact the Console adapter unconditionally calls a variant of `substr()` on the given `$text` to shorten it to the configured display width. With PHP 8.1 this fails, because native functions no longer accept `null` for a string parameter: > TypeError: grapheme_substr(): Argument #1 ($string) must be of type string, null given in […] Signed-off-by: Tim Düsterhus --- src/ProgressBar.php | 2 +- test/ProgressBarTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ProgressBar.php b/src/ProgressBar.php index 72abe2a..d98f20d 100644 --- a/src/ProgressBar.php +++ b/src/ProgressBar.php @@ -42,7 +42,7 @@ class ProgressBar * * @var string */ - protected $statusText = null; + protected $statusText = ''; /** * Adapter for the output diff --git a/test/ProgressBarTest.php b/test/ProgressBarTest.php index c3c5ebe..89f096e 100644 --- a/test/ProgressBarTest.php +++ b/test/ProgressBarTest.php @@ -80,6 +80,13 @@ public function testEtaZeroPercent() $this->assertEquals(null, $progressBar->getTimeRemaining()); } + public function testMissingTextIsNotNull() + { + $progressBar = $this->_getProgressBar(0, 100); + + $this->assertSame('', $progressBar->getText()); + } + // @codingStandardsIgnoreStart protected function _getProgressBar($min, $max, $persistenceNamespace = null) {