Browse Source

Output URLs whenever there is a request.

Outputting the Request data should depend on the request object, not the
server API. This changes the behavior in a CLI context, but unless users
are pushing requests around in their cron scripts this shouldn't be
a problem.

Update the tests to ensure the request related logging is covered.

Refs #8089
Mark Story 10 years ago
parent
commit
ff44e9e5ba
2 changed files with 13 additions and 9 deletions
  1. 8 8
      src/Error/BaseErrorHandler.php
  2. 5 1
      tests/TestCase/Error/ErrorHandlerTest.php

+ 8 - 8
src/Error/BaseErrorHandler.php

@@ -292,17 +292,17 @@ abstract class BaseErrorHandler
                 $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
             }
         }
-        if ((PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg')) {
-            $request = Router::getRequest();
-            if ($request) {
-                $message .= "\nRequest URL: " . $request->here();
 
-                $referer = $request->env('HTTP_REFERER');
-                if ($referer) {
-                    $message .= "\nReferer URL: " . $referer;
-                }
+        $request = Router::getRequest();
+        if ($request) {
+            $message .= "\nRequest URL: " . $request->here();
+
+            $referer = $request->env('HTTP_REFERER');
+            if ($referer) {
+                $message .= "\nReferer URL: " . $referer;
             }
         }
+
         if (!empty($config['trace'])) {
             $message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n";
         }

+ 5 - 1
tests/TestCase/Error/ErrorHandlerTest.php

@@ -86,6 +86,8 @@ class ErrorHandlerTest extends TestCase
 
         $request = new Request();
         $request->base = '';
+        $request->env('HTTP_REFERER', '/referer');
+
         Router::setRequestInfo($request);
         Configure::write('debug', true);
 
@@ -304,7 +306,9 @@ class ErrorHandlerTest extends TestCase
                     '[Cake\Routing\Exception\MissingControllerException] ' .
                     'Controller class Derp could not be found.'
                 ),
-                $this->stringContains('Exception Attributes:')
+                $this->stringContains('Exception Attributes:'),
+                $this->stringContains('Request URL:'),
+                $this->stringContains('Referer URL:')
             ));
 
         $this->_logger->expects($this->at(1))