Problem/Motivation
Found in #3644166: [META] Find and resolve external HTTP requests from core tests. Three kernel tests fetch from oembed.com and YouTube:
MediaSourceValidationTesthas a mock HTTP client, but sets it aftersetUp()already created the oEmbed services with the real client, so the mock is never used for oEmbed data.EntityLinksTest::testMediaEntity()saves YouTube media without any mocking.ProviderRepositoryTest::testNonExistingProviderDatabase()tests failure handling by requesting a host that does not exist and a missing file on oembed.com.
Steps to reproduce
Run these tests with the detector from #3644166: [META] Find and resolve external HTTP requests from core tests.
Proposed resolution
Use Guzzle's MockHandler with the existing oEmbed fixtures: set it before the oEmbed services are created in MediaSourceValidationTest (and assert it was used), add it to the oEmbed cases of EntityLinksTest, and have ProviderRepositoryTest mock a connection error and a 404.
Remaining tasks
Review the MR with the fix. The other MR adds the detector to show the requests are gone, and is not to be committed.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
Not needed.
LLM disclosure
LLM was used to diagnose this problem and develop solutions. The results were reviewed and adjusted as a human though.
Issue fork drupal-3644258
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
gábor hojtsyComment #5
gábor hojtsyComment #6
gábor hojtsyComment #7
quietone commentedI expected the testing only fixture to not have changes to the test files to show the problem. For example, MediaSourceValidationTest.php does not fail in the testing MR. I didn't look at the other files.
Comment #8
gábor hojtsy@quietone: Sorry, "testing only" was maybe a confusing name, I intended to mean not to commit/review that one. All of the fixes are in tests. What shows the problem is the request detector from #3644166: [META] Find and resolve external HTTP requests from core tests, which fails any test that makes an external HTTP request.
EntityLinksTest,MediaSourceValidationTestandProviderRepositoryTestfail. Between them they make 12 requests to oembed.com, oembed1.com, www.youtube.com and i.ytimg.com.I think once/if we fix all of these we should look if there is a clean way to add such a detector in the core tests. The way it currently works as you can see in !18130 is that it adds a condition to the runtime code in core/lib/Drupal/Core/Http/ClientFactory.php to log the requests in tests. So whether we want to ad that or have a better solution to regression-test this needs to be discussed. As the detector is the same across all the meta issue items, I did not intend to discuss that yet.
That said, we can also sequence this directly and add non-failing reporting somehow first to the tests, eg. add a separate testing job that runs all of the phpunit tests and fails with these and is allowed to fail. If that needs to be done first, then likely we need to postpone all of these and open that issue first instead of a followup after these for regression-testing.
Comment #9
catchFor me I think there's a limit to how much we should test the testing framework, we're not short of runtime code that needs better testing or other refactoring of existing tests. Having said that it's annoying having so many of these undetected for so long, so in this case probably worth a follow-up to see if we can find a way to do the detection without a runtime code change.