Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Extract extra info from headers_sent #13

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

undercloud
Copy link

@undercloud undercloud commented Mar 30, 2019

headers_sent allows you to define a file and a line that has undesirable output, otherwise it is impossible to identify and correct the error, there is not enough of this and it is difficult to debug, but the edit is very small, but gives many possibilities, I hope this edit will fall into the main branch, thanks!

https://www.php.net/manual/en/function.headers-sent.php

@@ -31,8 +31,9 @@ trait SapiEmitterTrait
*/
private function assertNoPreviousOutput()
{
if (headers_sent()) {
throw EmitterException::forHeadersSent();
$file = $line = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define on separate lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you need ... if not, please specify

@Xerkus
Copy link
Member

Xerkus commented Mar 31, 2019

@undercloud It is a new feature, please target develop branch. Also it needs tests to be accepted.

@undercloud undercloud changed the base branch from master to develop March 31, 2019 19:25
ob_get_clean();
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try it like this:

$this->expectException(EmitterException::class);
$this->expectExceptionMessage('Unable to emit response; headers already sent');
$this->expectExceptionMessage(sprintf(
    'output started at %s:%d',
     __FILE__,
     __LINE__ + 3
));
ob_start();
echo 'Unexpected Output';
try {
    $this->emitter->emit($response);
} catch (\Throwable $e) {
    throw $e;
} finally {
    ob_end_clean();
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, unsuccessfully ... I assume that sending headers is not called in the SAPI environment of tests, all my attempts at tests are unsuccessful ...

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-httphandlerrunner; a new issue has been opened at laminas/laminas-httphandlerrunner#1.

@weierophinney
Copy link
Member

This repository has been moved to laminas/laminas-httphandlerrunner. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-httphandlerrunner to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-httphandlerrunner.
  • In your clone of laminas/laminas-httphandlerrunner, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

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

Successfully merging this pull request may close these issues.

3 participants