Description
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
todev/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”.