From 677e117b97fc3280d49e368c45b9accf6515fa8f Mon Sep 17 00:00:00 2001 From: Steve Campbell Date: Mon, 19 Jun 2023 14:55:33 +0100 Subject: [PATCH] Fix strlen() being passed a null in ArcanistUnitConsoleRenderer.php Summary: Fix the following error in ArcanistUnitConsoleRenderer.php under PHP 8.1: ``` strlen(): Passing null to parameter #1 ($string) of type string is deprecated ``` Stack trace: ``` EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/src/error/PhutilErrorHandler.php:261] arcanist(head=master, ref.master=97e163187418, custom=4) #0 PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/unit/renderer/ArcanistUnitConsoleRenderer.php:15] #1 ArcanistUnitConsoleRenderer::renderUnitResult(ArcanistUnitTestResult) called at [/src/workflow/ArcanistUnitWorkflow.php:190] #2 ArcanistUnitWorkflow::run() called at [/scripts/arcanist.php:427] ``` Ref T15187 Test Plan: arc unit Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15187 Differential Revision: https://we.phorge.it/D25300 --- .../__tests__/ArcanistUnitTestResultTestCase.php | 13 +++++++++++++ src/unit/renderer/ArcanistUnitConsoleRenderer.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/unit/__tests__/ArcanistUnitTestResultTestCase.php b/src/unit/__tests__/ArcanistUnitTestResultTestCase.php index 7c4d43dd..7458af8f 100644 --- a/src/unit/__tests__/ArcanistUnitTestResultTestCase.php +++ b/src/unit/__tests__/ArcanistUnitTestResultTestCase.php @@ -40,4 +40,17 @@ final class ArcanistUnitTestResultTestCase extends PhutilTestCase { } } + public function testRenderer() { + $result = new ArcanistUnitTestResult(); + $result->setName('RendererTest'); + $result->setResult('pass'); + $result->setDuration(0.001); + $result->setUserData(''); + + $renderer = new ArcanistUnitConsoleRenderer(); + $output = $renderer->renderUnitResult($result); + $test_dscr = 'Renderer copes with null namespace'; + $this->assertTrue((bool)preg_match('/PASS/', $output), $test_dscr); + } + } diff --git a/src/unit/renderer/ArcanistUnitConsoleRenderer.php b/src/unit/renderer/ArcanistUnitConsoleRenderer.php index 729c4b8d..48a1d96f 100644 --- a/src/unit/renderer/ArcanistUnitConsoleRenderer.php +++ b/src/unit/renderer/ArcanistUnitConsoleRenderer.php @@ -12,7 +12,7 @@ final class ArcanistUnitConsoleRenderer extends ArcanistUnitRenderer { $test_name = $result->getName(); $test_namespace = $result->getNamespace(); - if (strlen($test_namespace)) { + if (phutil_nonempty_string($test_namespace)) { $test_name = $test_namespace.'::'.$test_name; }