Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code added to output #151

Open
szaleq opened this issue Jan 18, 2024 · 2 comments
Open

Code added to output #151

szaleq opened this issue Jan 18, 2024 · 2 comments

Comments

@szaleq
Copy link

szaleq commented Jan 18, 2024

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.

@anomiex
Copy link
Collaborator

anomiex commented Jan 18, 2024

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

@antecedent
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants