Problem/Motivation
Steps to reproduce:
- rm core/tests/Drupal/Tests/Component/Utility/XssTest.php
- phpunit --testsuite unit
And you see failures in Drupal\Tests\Core\Routing\RedirectDestinationTest
and Drupal\Tests\Core\Path\PathValidatorTest
. This is because Drupal\Tests\Component\Utility\UrlHelperTest
ends up with setting only http
as a valid protocol. When XssTest is around this fixes this before the tests that are failing are run.
This is mess. Statics are awful for unit tests.
Proposed resolution
As of Drupal 10.1.x the issue does not occur - but that's probably because of test ordering which is something we should not be relying.
The best solution here is to run tests that mess with statics in a separate process using PHPUnit's annotations. Since we use run-tests.sh on DrupalCI it was never affected because it runs each PHPUnit test individually.
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/a
Comment | File | Size | Author |
---|---|---|---|
#23 | 2503063-2-23.patch | 3.23 KB | alexpott |
| |||
#23 | 19-23-interdiff.txt | 1.74 KB | alexpott |
#19 | 2503063-2-19.patch | 2.26 KB | alexpott |
#2 | 2503063.2.patch | 2.79 KB | alexpott |
#2 | 2503063.2.will-fail.patch | 22.73 KB | alexpott |
Comments
Comment #1
alexpottWell this fixes the problem and ensures that UrlHelper does not having protocols bleed between tests.
Comment #2
alexpottI think we should add a PHPUnit side effect test so we catch this type of thing in d.o test runs.
Comment #4
dawehnerYes but ... why? Well, because we are running tests manually. Should we explain that?
Comment #5
alexpottSo now I'm pondering if we shouldn't just remove run-tests.sh's ability to run PHPUnit tests and just put everything into this test. In the long run it's best to encourage people to run phpunit tests using phpunit.
Comment #6
dawehnerHonestly? I'd just love!
The question is what do we do with the other tests: BrowserTestBase and KernelTestBase in the future. Running them like that could be problematic due to the speed limit?
I guess we really need the new testbot infrastructure
Then there is also the question how do we adapt the existing simpletest UI. Should we just render shell strings and remove the checkbox for PHPUnit tests?
Comment #7
mgiffordPatch no longer applies.
Comment #19
alexpottWhile the failure no longer happens - probably because test ordering has changed in some way I still think that making some sort of fix here it warranted.
The simplest fix is to mark tests which change the static as needing to run in a separate process.
Comment #20
alexpottComment #21
LendudeThis came up as a daily Bug smash target, hence the reviving.
Checked and these 4 spots are the only tests that mess with
UrlHelper::setAllowedProtocols
, so that seems like a good fix.Tried to reproduce the issue too, but my setup gets stuck at 49% while running all the unit tests ¯\_(ツ)_/¯
Comment #23
alexpottInteresting, we really shouldn't be setting expectations or using the container in a data provider.
Comment #24
LendudeNice bit of hardening coming out of this then, looks good and comes back green
Comment #26
catchCommitted/pushed to 10.1.x and cherry-picked back through to 9.4.x, thanks!