Skip to content

Commit

Permalink
Define AMP_DEBUG through environment
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 2, 2017
1 parent c260e2e commit 745a95b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ matrix:
- php: nightly
fast_finish: true

env:
- AMP_DEBUG=true

before_install:
- phpenv config-rm xdebug.ini || echo "No xdebug config."

Expand Down
9 changes: 6 additions & 3 deletions lib/Internal/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,18 @@ private function resolve($value = null) {
$trace = formatStacktrace($this->resolutionTrace);
$message .= ". Previous resolution trace:\n\n{$trace}\n\n";
} else {
$message .= ", define const AMP_DEBUG = true and enable assertions for a stacktrace of the previous resolution.";
// @codeCoverageIgnoreStart
$message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions "
. "for a stacktrace of the previous resolution.";
// @codeCoverageIgnoreEnd
}

throw new \Error($message);
}

\assert((function () {
if (\defined("AMP_DEBUG") && \AMP_DEBUG) {
$trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
if (\getenv("AMP_DEBUG") || (\defined("AMP_DEBUG") && \AMP_DEBUG)) {
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
\array_shift($trace); // remove current closure
$this->resolutionTrace = $trace;
}
Expand Down
13 changes: 6 additions & 7 deletions lib/Internal/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,23 @@ private function complete() {
$message = "Iterator has already been completed";

if (isset($this->resolutionTrace)) {
// @codeCoverageIgnoreStart
$trace = formatStacktrace($this->resolutionTrace);
$message .= ". Previous completion trace:\n\n{$trace}\n\n";
// @codeCoverageIgnoreEnd
} else {
$message .= ", define const AMP_DEBUG = true and enable assertions for a stacktrace of the previous completion.";
// @codeCoverageIgnoreStart
$message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions "
. "for a stacktrace of the previous resolution.";
// @codeCoverageIgnoreEnd
}

throw new \Error($message);
}

\assert((function () {
if (\defined("AMP_DEBUG") && \AMP_DEBUG) {
// @codeCoverageIgnoreStart
$trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
if (\getenv("AMP_DEBUG") || (\defined("AMP_DEBUG") && \AMP_DEBUG)) {
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
\array_shift($trace); // remove current closure
$this->resolutionTrace = $trace;
// @codeCoverageIgnoreEnd
}

return true;
Expand Down

0 comments on commit 745a95b

Please sign in to comment.