magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

[Integration Tests] Configs from the global config file are resetted before any test #39230

Open stollr opened 1 month ago

stollr commented 1 month ago

Preconditions and environment

In dev/tests/integration/phpunit.xml there is the constant TESTS_GLOBAL_CONFIG_FILE defined, which allows to define a php file, which can be used to provide some config values, which are stored in the Magento\TestFramework\App\Config.

This file is correctly loaded during initialization of the test application.

But before any test is started the startTest event is fired, which calls Magento\TestFramework\Isolation\AppConfig::startTest() where the config is resetted and thus the config entries of the TESTS_GLOBAL_CONFIG_FILE get lost.

I know about the @magentoConfigFixture annotation. But I need to configure environment dependant credentials and I don't want to hardcode them in the test files.

Magento version: 2.4.7-p2 PHP version: 8.3

Steps to reproduce

use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Type; use Magento\Framework\ObjectManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase;

class TokenManagerTest extends TestCase { private ObjectManagerInterface $objectManager;

protected function setUp(): void
{
    $this->objectManager = Bootstrap::getObjectManager();
}

public function testGetToken(): void
{
    $context = $this->objectManager->get(\Magento\Framework\App\Helper\Context::class);
    $value = $context->getScopeConfig()->getValue('test/test/test');

    $this->assertTrue($value); // fails because $value is null
}

}


- Run the test

### Expected result

`$value` is `true` and the test succeeds

### Actual result

`$value` is `null` and the test fails.

### Additional information

_No response_

### Release note

_No response_

### Triage and priority

- [ ] Severity: **S0** _- Affects critical data or functionality and leaves users without workaround._
- [ ] Severity: **S1** _- Affects critical data or functionality and forces users to employ a workaround._
- [X] Severity: **S2** _- Affects non-critical data or functionality and forces users to employ a workaround._
- [ ] Severity: **S3** _- Affects non-critical data or functionality and does not force users to employ a workaround._
- [ ] Severity: **S4** _- Affects aesthetics, professional look and feel, “quality” or “usability”._
m2-assistant[bot] commented 1 month ago

Hi @stollr. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

stollr commented 1 month ago

Btw. the usage of the config-global.php for this case is documented here.

m2-assistant[bot] commented 1 month ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 1 month ago

Hello @stollr,

Thanks for the report and collaboration!

We have tried to reproduce the issue in latest 2.4-develop branch, and we are getting the below error:

image

Are you talking about the same issue in the main description?

Thanks

stollr commented 1 month ago

@engcom-Hotel Yes, this is the same issue.

engcom-Hotel commented 3 weeks ago

Thanks @stollr, for the reply!

We are confirming the issue for further processing. Additionally, I'd like to mention that community members are welcome to pick up issues and submit a fix as a Community PR in this repository.

Thanks

github-jira-sync-bot commented 3 weeks ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13237 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 weeks ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.