Skip to content

Proper way to add a property to a mock object? #5099

@come-nc

Description

@come-nc
Q A
PHPUnit version 9.5.26
PHP version 8.2 RC
Installation Method Composer

Summary

When setting a public property on a mock object with $object->prop = 'value';, PHP >= 8.2 complains about a dynamic var.

Current behavior

Creation of dynamic property Mock_IRequest_a01db3a3::$server is deprecated

How to reproduce

		$this->request = $this->createMock(IRequest::class);
		$this->request->server['PHP_AUTH_USER'] = 'clientId';

Expected behavior

No error, or some other way to ask a mock object to return a given value for a public property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions