• Resolved xoogu

    (@xoogu)


    I’m testing some code using PHPUnit, and when my code uses
    wp_die(new WP_Error('errorCode', 'errorMessage'));
    I get the error:
    Error: Wrong parameters for WPDieException([string $message [, long $code [, Throwable $previous = NULL]]])
    If I change my code to:
    wp_die('errorMessage');
    Then it works correctly (I get WPDieException: errorMessage).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Joey

    (@leglesslizard)

    Hey,

    There is nothing wrong with the code
    wp_die(new WP_Error('errorCode', 'errorMessage'));

    So it must be something to do with the test environment. Maybe you don’t have access to everything you need?

    My understanding is the unit testing should be about isolating methods, however, and so ideally you wouldn’t be calling other methods but mocking them instead and only testing the code within that one method.

    Regards

    Moderator Dion Hulse

    (@dd32)

    Meta Developer

    Hi @xoogu,

    Thanks for reporting this, it makes sense that wp_die() should handle the same parameters in both the default and unit testing configurations.
    I’ve opened a core ticket to track this here: https://core.trac.www.ads-software.com/ticket/36166

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Passing WP_Error instance to wp_die when unit testing doesn't work’ is closed to new replies.