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.49k stars 9.3k forks source link

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

Open stollr opened 3 hours ago

stollr commented 3 hours 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 3 hours 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.