Problem/Motivation
There is an undefined property error during a test run using run-tests.sh
Drupal\Tests\Component\DrupalComponentTest 2 passes
PHP Notice: Undefined property: Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::$results in /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh on line 633
Notice: Undefined property: Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest::$results in /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh on line 633
There is an example here: https://qa.drupal.org/pifr/test/908228 If you expand review log and search for "undefined property".
ContainerAwareEventDispatcherTest
a verbatim copy of the Symfony EventDispatcherTest
and therefore does not inherit from Drupal\Tests\UnitTestCase
but directly from PHPUnit_Framework_TestCase
. This has been supported by the GUI test runner since #697760: Replace getInfo() in tests with native phpDoc + annotations (following PHPUnit). However, the run-test.sh
script was left behind in that issue. As a result run-test.sh
assumes that ContainerAwareEventDispatcherTest
is a web-test instead of php-unit and chooses the wrong method of execution.
The issue went largely unnoticed until #2189345: run-tests.sh should exit with a failure code if any tests failed got committed. Since then whenever some test fails, pifr reports the unhelpful message Failed to run tests: failed during invocation of run-tests.sh. instead of X pass(es), Y fail(s), and Z exception(s). Also the detailed table of test-results is missing on qa.drupal.org, rather only the test log is displayed.
Proposed resolution
Update run-tests.sh
to be aware of PHPUnit_Framework_TestCase
.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Beta phase evaluation
Issue priority | Critical because it fixes a bug in the testbot that causes all test runs to fail. |
---|
Comment | File | Size | Author |
---|---|---|---|
#22 | 2376039-make-run-test-aware-of-vanilla-phpunit-22.diff | 1.18 KB | znerol |
#8 | interdiff.txt | 1.26 KB | znerol |
#8 | 2376039-make-run-test-aware-of-vanilla-phpunit-8.diff | 1.26 KB | znerol |
#2 | 2376039-make-run-test-aware-of-vanilla-phpunit.diff | 1.26 KB | znerol |
Comments
Comment #1
benjy CreditAttribution: benjy commentedComment #2
znerol CreditAttribution: znerol commentedThis is due to
run-tests.sh
executingContainerAwareEventDispatcherTest
as a simpletest (web-test) instead of as a unit-test.Comment #3
znerol CreditAttribution: znerol commentedNote that the GUI test runner has been updated to support native
PHPUnit_Framework_TestCase
in #697760: Replace getInfo() in tests with native phpDoc + annotations (following PHPUnit), seems that test discovery of therun-test.sh
script was forgotten then.Comment #4
znerol CreditAttribution: znerol commentedNote also that since #2189345: run-tests.sh should exit with a failure code if any tests failed, pifr now reports "Failed to run tests: failed during invocation of run-tests.sh." if anything fails in addition to the
ContainerAwareEventDispatcherTest
. Raising to critical, because this makes it rather painful to examine test failures on qa.drupal.org.Comment #5
Wim Leers+1 to #4. Another example of where this happens: https://qa.drupal.org/pifr/test/910268.
Comment #6
Mile23Put a
\
in front of\PHPUnit_Framework_TestCase
in both places, and you get an RTBC from me.Comment #7
Mile23Comment #8
znerol CreditAttribution: znerol commentedComment #9
Mile23Delightful. :-)
Comment #10
Gábor HojtsyOh gosh this has been obscuring test results for every single one of my patches today :/ Thanks a lot folks!
Comment #11
BerdirNote that an existing issue was open since last may or so with an identical patch: #2225999: Drupal PHPUnit tests should extend UnitTestCase, not PHPUnit_Framework_TestCase and a lot of discussion.
Comment #12
BerdirAlso, do we have an example somewhere that this change actually fixes the error reporting? Like a patch that includes this change and has fails...
Comment #13
Mile23I RTBC'd not because of error reporting (or bikeshedding... :-)) but because I want passing tests to pass the testbot.
Is the easiest way to accomplish that by changing
run-tests.sh
? Or by changingContainerAwareEventDispatcherTest
?Comment #14
alexpottI can reproduce by passing the following to run-tests.sh
--class 'Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest'
. Giving myself and @Wim Leers commit credit for the identical work in #2225999: Drupal PHPUnit tests should extend UnitTestCase, not PHPUnit_Framework_TestCase.This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed cbc449b and pushed to 8.0.x. Thanks!
Comment #16
znerol CreditAttribution: znerol commentedRe #11: I assume the main reason for having to subclass
PHPUnit_Framework_TestCase
wasstatic function getInfo()
. This was only fixed in July by #697760: Replace getInfo() in tests with native phpDoc + annotations (following PHPUnit). The discussion in #2225999: Drupal PHPUnit tests should extend UnitTestCase, not PHPUnit_Framework_TestCase predates that. Also in the meantime #2270323: Remove DRUPAL_ROOT constant redefinitions from unit tests got in.I also tested
run-test.sh --list
without and with the patch and the output is identical, so it does not look like test discovery is affected (i.e.PHPUnit_Framework_TestCase
in vendor are not detected).Re #12: Good call: #2320269-50: IGNORE: Patch testing issue (this is expected to throw one exception in
ConfigImportAllTest
).Comment #17
znerol CreditAttribution: znerol commentedOh, #2320269-50: IGNORE: Patch testing issue ran through and the problem is not solved, it still says Failed to run tests: failed during invocation of run-tests.sh despite only one exception thrown and zero fails. Seems like pifr also needs to be updated for #2189345: run-tests.sh should exit with a failure code if any tests failed.
Comment #18
BerdirYeah, I don't think this had anything to do with that problem but I wasn't sure so I asked in #12 :)
This error happened all the time, also in successful results, if it would have been related to the return status, then it would have always failed?
Happy that this fixed, was open for a long time, but not sure if the "Critical" was correct in retrospective and should be changed again? But I'm also OK it was critical for having notices in all test results and not properly running this test..
Comment #20
alexpottI had to revert this to revert #2189345: run-tests.sh should exit with a failure code if any tests failed. The approach in this patch is still valid and could go in before that one.
Comment #21
znerol CreditAttribution: znerol commentedThe patch in #2225999: Drupal PHPUnit tests should extend UnitTestCase, not PHPUnit_Framework_TestCase applies cleanly and the other issue has the proper name. Someone just could RTBC the other one :)
Update: Nevermind, that just got closed as a duplicate.
Comment #22
znerol CreditAttribution: znerol commentedReroll.
Comment #23
dawehnerAlright, perfect!
Comment #24
benjy CreditAttribution: benjy commentedOnce this goes in, what else needs to happen to get #2189345: run-tests.sh should exit with a failure code if any tests failed committed again? It sounds per #18, that we have another similar fail issue somewhere?
Comment #25
alexpottLeaving this at critical because without this patch we are not running a test. This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 290712e and pushed to 8.0.x. Thanks!