When running php unit test case i got below error

PHPUnit\Framework\Exception: Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in vendor/symfony/console/Helper/Helper.php:137.

Please help

2 Answers 2


This error occurs because passing null to the preg_replace() function as the third argument is deprecated in PHP 8.0. To resolve this error, you need to pass an empty string instead of null.

To fix this error in Symfony console, you can upgrade the symfony/console package to the latest version. This issue has been fixed in Symfony console version 4.4.23, 5.2.11, and 5.3.0.

You can update the symfony/console package by running the following command:

composer require symfony/console:^5.2.11

After updating the package, you can run the PHPUnit test case again to verify that the error has been resolved.

  • can you please tell how to check my current symfony version
    – Jaisa
    Commented Mar 31, 2023 at 12:58
  • magento2.4.5-p1 supports only symfony/console version 4.4, my version is 4.4 only
    – Jaisa
    Commented Apr 8, 2023 at 14:29

The error message you received suggests that you are using a deprecated function in the Symfony Console component, specifically preg_replace(). This error can be resolved by upgrading your version of Symfony Console to a version that no longer uses this deprecated function.

To resolve this issue, you can follow these steps:

  1. Update your composer.json file to require the latest version of Symfony Console. You can do this by adding or modifying the following line in the "require" section of your composer.json file:

    "symfony/console": "^5.4"

  2. Run the following command to update your dependencies:

    composer update

  3. Once the update is complete, try running your PHPUnit test case again.

Note: It's always a good practice to test your application on a development environment before upgrading any dependencies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.