Doubling interfaces and abstract properties with property hooks
Author: davidbyoungCreated Sep 13, 2024Updated Aug 27, 2025
LabelsFeature Request
With PHP 8.4 coming up, we need a way of doubling interface property and abstract property hooks. A similar issue is open in PHPUnit. For example, we may have the following interface:
interface Foo
{
public string $gettable { get; }
public string $gettableAndSettable { get; set; }
public string $settable { set; }
}or similarly, this abstract class:
abstract class Foo
{
abstract public string $gettable { get; }
abstract public string $gettableAndSettable { get; set; }
abstract public string $settable { set; }
}We need the ability to mock what getters return and what setters receive, eg
// Arrange
$foo = Mockery::mock(Foo::class);
// Not a real method, but conveys what I'm trying to accomplish
$foo->shouldReceivePropertyGetter('gettable')
->andReturn('bar');
$foo->shouldReceivePropertyGetter('gettableAndSettable')
->andReturn('baz');
// Not a real method, but conveys what I'm trying to accomplish
$foo->shouldReceivePropertySetter('gettableAndSettable')
->with('qux');
$foo->shouldReceivePropertySetter('settable')
->with('quz');
// Act
$foo->gettable; // Should return 'bar'
$foo->gettableAndSettable; // Should return 'baz'
$foo->gettableAndSettable = 'qux';
$foo->settable = 'quz';Source: mockery/mockery