Problem/Motivation

PHP Fatal error:  Call to a member function getCollectCodeCoverageInformation() on a non-object in /var/lib/drupaltestbot/sites/default/files/checkout/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php on line 58
PHP Warning:  Invalid argument supplied for foreach() in /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh on line 585

Warning: Invalid argument supplied for foreach() in /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh on line 585

This happens when Payment 8.x-2.x. PHPUnit does not document that test results do not always have to exist, so based on the documentation the current code is correct, but in practice it causes errors.

Proposed resolution

Check for the existence of the results.

Remaining tasks

None.

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#1 drupal_2443885_1.patch772 bytesXano
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Status: Active » Needs review
FileSize
772 bytes
dawehner’s picture

@xano
Just curious, is that for stuff like skipped tests or is this really for a test class without any test method?

Xano’s picture

I cannot reproduce the failure locally, neither by running unit tests through PHPUnit directly or through run-tests.sh, so I can't really debug. The listener class is to make sure all @covers annotations are correct, but that's something that PHPUnit has been doing itself on my local machines for years now.

dawehner’s picture

@Xaxo
Can you point to the test code which fails?

Xano’s picture

The Payment 8.x-2.x branch test results are the only source of information I have, unfortunately. I tried to reproduce this locally to pinpoint the exact cause of the problem, but whatever I do, It Just Works™.

Arla’s picture

I had the very same problem and opened #2442125: Unclear error message for non-test class in Unit namespace As stated there, I could reproduce locally with run-tests.sh --class 'Drupal\Tests\mymodule\Unit\ClassWithoutTests'.

Xano’s picture

I have a number of base test classes, one of which wasn't marked abstract, which means it was executed. The reason this went wrong on the testbot only is probably that that's the only situation in which the listener is used.

YesCT’s picture

YesCT’s picture

Title: DrupalStandardsListener causes errors when it cannot retrieve test results » DrupalStandardsListener causes errors when it cannot retrieve test results. Missing abstract keyword.

updating title. hopefully will help others find the answer when they have a similar problem.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.
I can confirm that a locally run test-class with no tests results in the error.
The problem is fixed with the patch. So it is RTBC for me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Test code is not frozen in beta.

+++ b/core/tests/Drupal/Tests/Standards/DrupalStandardsListener.php
@@ -55,7 +55,7 @@ protected function classExists($class) {
     // If we're generating a coverage report already, don't do anything here.
-    if ($test->getTestResultObject()->getCollectCodeCoverageInformation()) {
+    if ($test->getTestResultObject() && $test->getTestResultObject()->getCollectCodeCoverageInformation()) {

Comment could do with an update...

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

I'm wrong. Thanks @neclimdul for point out :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Test code is not frozen in beta. Committed 1cff097 and pushed to 8.0.x. Thanks!

  • alexpott committed 1cff097 on
    Issue #2443885 by Xano: DrupalStandardsListener causes errors when it...

Status: Fixed » Closed (fixed)

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