I upgraded my website from magento 2.3.6-p1 to 2.4.5-p1,

When i run php unit test case for my custom module(This module overides the CreatePassword.php file from Customer module) throws error from Session manager like below

TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object

/var/www/html/project/Vendor_Name/src/vendor/magento/framework/Session/SessionManager.php:151 /var/www/html/project/Vendor_Name/src/vendor/magento/module-customer/Controller/Account/CreatePassword.php:100

  • which php version you are using?
    – Mehran
    May 22, 2023 at 11:25
  • PHP version is 8.1
    – jaisa2
    May 22, 2023 at 14:17

1 Answer 1


Cause of Issue :

vendor/magento/framework/Session/SessionManager.php:151 SessionManager.php:151

First array member is $this->storage which would be null and hence you would be getting the error that it is not a valid class name or object.

vendor/magento/module-customer/Controller/Account/CreatePassword.php:100 CreatePassword.php:100

When it tries to get rp_customer_id value using the getRpCustomerId method, __call method of SessionManager gets called to fetch data from session storage. It wouldn't work with PHPUnit Test as the storage will be null.

How to fix the issue :
Need to create mock object of Customer Session Model and set the return value for getRpCustomerId method. Hence, it will fetch the data from the mock.

Create Mock of \Magento\Customer\Model\Session class

$this->sessionMock = $this->getMockBuilder(Session::class)

Set return value for getRpCustomerId


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.