Skip to content

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

Open
@stollr

Description

@stollr

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

  • Copy dev/tests/integration/etc/config-global.php.dist to dev/tests/integration/etc/config-global.php
  • Add a config setting to the config file, like 'test/test/test' => true,
  • Then add a test file, like this
namespace Acme\ApiTokenManager\Test\Integration\Adapter;

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.
  • 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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: TestFrameworkIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReported on 2.4.7-p2Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions