Skip to content

Is it possible to double get property, while set property is private? #6393

@Belorusov

Description

@Belorusov

PhpUnit Version: 12.4.1

I got following class and want to mock it public get property hook

class Example
{
    public function __construct(
        private(set) string $property {
               get => $this->property;
        }
    ) {
    }
}

$example = $this->createMock(Example::class);
$example
    ->expects($this->once())
    ->method(PropertyHook::get('property'))
    ->willReturn('test');

Why it's not possible and gives me an error. We just want to mock public get hook, not private.[PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException] Trying to configure method "property" which cannot be configured because it does not exist, has not been specified, is final, or is static

It's a bit confusing...

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/test-doublesTest Stubs and Mock Objectsversion/11Something affects PHPUnit 11version/12Something affects PHPUnit 12

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions