Skip to content

Code added to output #151

@szaleq

Description

@szaleq

I'm testing a method, which echoes some content (it's a widget for an Elementor WordPress plugin). Since this method does not return anything, and the only way to check if it works properly is to check what it prints to the output, I've designed a test which uses output buffering to capture what the method echoes and test its value. This worked well but suddenly this tests started to fail because there is some patchwork code added to my buffered output - in each test the output is suffixed with this string: \Patchwork\CodeManipulation\Stream::reinstateWrapper();.

Here is a simplified test code (using Pest):

it('renders the widget', function () {
    ob_start();

    $this->widget->render();

    expect(ob_get_clean())->toEqual('assumed_render_result');
});

For example, if my widget's render() method had this code:

echo 'assumed_render_result';

the test should pass. Instead it fails, because the actual output is:
assumed_render_result;\Patchwork\CodeManipulation\Stream::reinstateWrapper();

Why is that? Is is some bug in Patchwork or am I missing something?

Here I found this code in source:

const STREAM_WRAPPER_REINSTATEMENT_CODE = '\Patchwork\CodeManipulation\Stream::reinstateWrapper();';

but I don't understand why it gets appended to my output buffering result and how to avoid id.

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