Skip to content

Requesting recipes on how to deal with setting properties on Mocks with PHP 8.2+ #1197

@jrfnl

Description

@jrfnl

PHP 8.2 deprecated the use of dynamic properties. This impacts the use of Mockery when using anonymous mocks or mocks for classes which are not available.

The remaining 11 test failures for Mockery itself on PHP 8.2 are all related to this.

I'll be the first to admit I'm no Mockery expert, so I've been experimenting with how to work round the deprecation and so far I've not had much luck finding elegant solutions.

Now of course, one shouldn't mock what you do not own, but there are test situations where certain external dependencies (framework) may not be available during testing, so there's not much which can done about that.

Findings so far:

  • Making the mock extend stdClass doesn't seem to work as this seems to run into trouble when the method under test has a class based parameter type declaration.
  • Using Mockery::namedMock() and having the named mock extend stdClass, works for the first test case, but that's it. (also noted as such in the documentation).
    Re-using the mock object isn't really an option as the object won't be "clean" anymore if properties are being assigned from the tests.
  • Along the same lines, using alias: mocks would require most tests to run in a separate process, which makes the test suite a lot slower as well as less stable.

Suggestions and "recipes" to solve this very welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAn error or unexpected behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions