magento2: Integration tests can break because they run into "exit" statement when using secure base URL

Summary

When the base URL is set to a secure https:// URL and the integration tests are run via CLI and PHPunit the _checkShouldBeSecure runs into an exit

Example

The error disguises itself as “Some transactions have not been committed or rolled back during integration tests”

Such exit statements are super hard to debug, especially when appearing on CI where no Xdebug is available. Even with Xdebug it’s hard to find the exit statement as nobody expects it in modern, testable code.

This is the problematic line:

https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/App/Router/Base.php#L366

Preconditions

have a web/secure/base_url or web/unsecure/base_url set in your Integrations tests that starts with https://

Proposed solution

  1. The exit should be removed completely
  2. Or: Add a special case for PHPUnit not to run into the exit which cannot be traced back

Additionally, also other usages of the exit statement should be checked https://github.com/magento/magento2/search?q=Magento2.Security.LanguageConstruct.ExitUsage&unscoped_q=Magento2.Security.LanguageConstruct.ExitUsage

See also https://magento.stackexchange.com/a/314662/81

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 18 (12 by maintainers)

Most upvoted comments

Hello @amenk,

As the issue is not reproducible for us by trying various ways. And you mentioned here that the issue is unable to reproduce, hence we are closing this issue for now.

Thanks

While I understand that all issues are tried to be reproduced, I still suggest the exit is removed, as this is bad practice - even this is not 100% reproducible in current Magento versions. Is the exit() still there?