antecedent/patchwork

Code added to output

szaleq opened this issue · 2 comments

szaleq commented

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.

Can you provide a minimal test case (e.g. as a zip file or small github repo) that reproduces this?

This does seem like a bug in Patchwork. I agree that a minimal test case would be very helpful in pinning it down.