Mock class method with TestHelpers::createClass

Created on 26 June 2024, 5 months ago
Updated 14 August 2024, 3 months ago

Problem/Motivation

Hello,
Currently, I see there is no way to mock methods from original class when class is mocked with TestHelpers::createClass method.

The alternative approach is to use TestHelpers::createPartialMockWithConstructor

Proposed resolution

It will be good to add additional argument to TestHelpers::createClass method which accepts method names to mock.

Feature request
Status

Closed: won't fix

Version

1.3

Component

Code

Created by

🇮🇳India gaurav_manerkar Vasco Da Gama, Goa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gaurav_manerkar
  • Status changed to Closed: won't fix 3 months ago
  • 🇦🇲Armenia murz Yerevan, Armenia

    I checked this and seems it's impossible to implement.

    The function TestHelpers::createClass() calls the static method ::create() which creates a new instance of the class on its own, and I have no idea how to put there a mock instead of the original class.

    And the workaround is to use the TestHelpers::createPartialMockWithConstructor() instead, and do all the things from the method ::create() manually.

    So, if you have some ideas about how to implement this - please share and reopen.

Production build 0.71.5 2024