If a module fails to implement the getInfo() method on a unit test case, UnitTestCase::getInfo() will throw the following exception:

RuntimeException: Sub-class must implement the getInfo method! in Drupal\Tests\UnitTestCase::getInfo() (line 40 of core/tests/Drupal/Tests/UnitTestCase.php).

This is not diagnostically helpful, because it doesn't tell you what class is actually missing the method. The exception message should indicate the class with the problem. Patch to follow.

Comments

traviscarden’s picture

Title: "Sub-class must implement the getInfo method" not a helpful exception mesage » "Sub-class must implement the getInfo method" not a helpful exception message
Assigned: traviscarden » Unassigned
Status: Active » Needs review
StatusFileSize
new648 bytes

Maybe something like this. This would result in an exception message like the following:

Error message
RuntimeException: Drupal\mymodule\Tests\MymoduleTest must implement the getInfo method! in Drupal\Tests\UnitTestCase::getInfo() (line 40 of core/tests/Drupal/Tests/UnitTestCase.php).

traviscarden’s picture

StatusFileSize
new702 bytes

Wait, raw string concatenation? What was I doing? New patch.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice idea!

chx’s picture

We learn something every day. I never knew static was available in such a way.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Let's use String::format() here instead of format_string().

internetdevels’s picture

Status: Needs work » Needs review
StatusFileSize
new824 bytes
new884 bytes

New try.

xano’s picture

StatusFileSize
new1.29 KB
new1.66 KB

Let's make clear what method we are actually talking about. Not everybody understands OOP as well as we do. I also updated Simpletest's TestBase, which throws an identical exception for the same reason.

headli’s picture

Status: Needs review » Reviewed & tested by the community

I've proved both exception declarations, which looks well for me. The exception message is built in the same way on both declarations.

dawehner’s picture

I really like this!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6b393bb and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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