Fatal error: Call to a member function setResponse() on a non-object in core/lib/Drupal/Core/ExceptionController.php on line 89

$event is not defined. Easy fix, patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

Component: wscci » base system
Status: Needs review » Reviewed & tested by the community
Issue tags: +WSCCI

Refiling. (The wscci component is vestigial.)

Also, RTBC. :-)

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Let's get some tests for this.

klausi’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.48 KB
2.07 KB

Now with tests. Could not find a suiting test class, so I created a new ExceptionControllerTest in system module.

Status: Needs review » Needs work

The last submitted patch, 1816582-3-exception-405-testonly.patch, failed testing.

klausi’s picture

Status: Needs work » Needs review

Test only patch fails as expected :-)

Crell’s picture

+++ b/core/modules/system/lib/Drupal/system/Tests/System/ExceptionControllerTest.php
@@ -0,0 +1,37 @@
+  public function test405HTML() {
+    $exception_controller = new ExceptionController(new ContentNegotiation());
+    $response = $exception_controller->on405Html(new FlattenException(), new Request());
+    $this->assertEqual($response->getStatusCode(), 405, 'HTTP status of response is correct.');
+    $this->assertEqual($response->getContent(), 'Method Not Allowed', 'HTTP response body is correct.');
+  }

I'm unclear how this is testing the behavior of the request. We're directly calling an internal method, on405Html, which is too deep. That's an implementation detail. Rather, we need to call the actual controller method of ExceptionController() and confirm that we get back the correct Response object.

klausi’s picture

Sure, now using the execute() method of the ExceptionController.

Status: Needs review » Needs work

The last submitted patch, 1816582-7-exception-405.patch, failed testing.

Crell’s picture

+++ b/core/modules/system/lib/Drupal/system/Tests/System/ExceptionControllerTest.php
@@ -0,0 +1,40 @@
+    $exception = new Exception('Test exception');

This needs to be new \Exception('Test exception').

klausi’s picture

Status: Needs work » Needs review
FileSize
2.2 KB

Of course, I thought the backslashes were optional but obviously PHP requires them.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

In a namespaced file, classes sans-prefix are assumed to be in the current namespace if not "use"d. So PHP was converting "Exception" to "Drupal\system\Test\Exception, which of course doesn't exist.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Will push at the end of my commit-spree.

Automatically closed -- issue fixed for 2 weeks with no activity.