Unable to run \Magento\Downloadable\Test\Unit\Helper\DownloadTest without internet connection / dns resolution #23521
Labels
Component: Test
Fixed in 2.4.x
The issue has been fixed in 2.4-develop branch
Issue: Clear Description
Gate 2 Passed. Manual verification of the issue description passed
Issue: Confirmed
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed
Issue: Format is valid
Gate 1 Passed. Automatic verification of issue format passed
Issue: Ready for Work
Gate 4. Acknowledged. Issue is added to backlog and ready for development
Reproduced on 2.3.x
The issue has been reproduced on latest 2.3 release
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
PHPUnit\Framework\Exception: Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/adrianmartinez/Sites/2.3/magento/vendor/magento/module-downloadable/Helper/Download.php:264.
Extended description
This behaviour cannot be reproduced in 2.2.8, test passes even if there is no internet connection. Comparing code both versions, I've seen this snippet of code has been added in new version of tested class
\Magento\Downloadable\Helper\Download
:This new code looks quite risky and not safe, I mean, even if problem is the test not passing, this piece of code has some assumptions that can break execution at any time.
First of all, test relies on a test url:
\Magento\Downloadable\Test\Unit\Helper\DownloadTest::URL = 'http://example.com'
, that may exist or not, or could be down at any time. This means this test could even fail with internet connection if that site is down or DNS servers are not available.In second place, it tries to extract headers using
get_headers
php built-in function, and passes the result directly toarray_change_key_case
, without any kind of check.get_headers
may emit a warning if it is not able to get header of supplied url, but even if silenced with@get_headers
, execution throws another warning due toget_headers
returning false instead of an array, andarray_change_key_case
complaining about receiving a boolean parameter instead of an array:I think that piece of code should be refactored through a HeadersResolver (or another more appropriate name), responsible of returning always a consistent return value when requested for some headers (always return an array), and use this new class in \Magento\Downloadable\Helper\Download, so it can be mocked for testing.
The text was updated successfully, but these errors were encountered: