Skip to content

Support for decorating runTest function #6172

@albertcht

Description

@albertcht

In my use case, I'd like to provide a convenient way for developers to run their test functions in coroutine containers like below:

class FooTest extends TestCase
{
    use RunTestsInCoroutine;

    // this test function is expected to be executed inside coroutine container
    public function testFoo()
    {
        //...
    }
}

For my current implementation, I try to use setName function to proxy the real test function. By this way the test function will be proxied and wrapped in coroutine container in the proxied function.

final protected function runTest(): mixed
{
    if ($this->shouldRunInCoroutine()) {
        $this->realTestName = $this->name();
        parent::setName('runTestsInCoroutine');
    }

    return parent::runTest();
} 

final protected function runTestsInCoroutine(...$arguments)
{
    parent::setName($this->realTestName);

    Coroutine\run(
        fn () => $this->{$this->realTestName}(...$arguments)
    );
}

However, I found this approach is not going to work any more because runTest function is marked private in: 8f0f820

I was wondering what the best practice is to proxy the test function to decorate the test functions.

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