i am writing integration tests for my custom module that has a configuration field type obscure
.
in test file app/code/Foo/Bar/Test/Integration/Model/ConfigTest.php
i have code:
<?php
namespace FooBarTestIntegrationModel;
use FooBarModelConfig;
use MagentoFrameworkObjectManagerInterface;
use MagentoTestFrameworkHelperBootstrap;
use PHPUnitFrameworkTestCase;
class ConfigTest extends TestCase
{
private ?ObjectManagerInterface $objectManager;
private ?Config $config;
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->config = $this->objectManager->get(Config::class);
}
/**
* @test
* @magentoConfigFixture default_website foo_module/bar_api_config/site_key 1x0000000000AA
*/
public function get_site_key()
{
$this->assertEquals('1x0000000000AA', $this->config->getSiteKey());
}
}
And in app/code/Foo/Bar/Model/Config.php
file i have method:
public function getSiteKey(): ?string
{
return $this->config->getValue('foo_module/bar_api_config/site_key', ScopeInterface::SCOPE_WEBSITE);
}
And at app/code/Foo/Bar/etc/adminhtml/system.xml
:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="foo_module" translate="label" type="text" sortOrder="700" showInDefault="1"
showInWebsite="1" showInStore="1">
<resource>Foo_Bar::config</resource>
<group id="bar_api_config" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="site_key" translate="label" type="obscure" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Sitekey</label>
<validate>required-entry</validate>
<backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model>
</field>
</group>
</section>
</system>
</config>
When testcase execute it always return empty ""
no matter whatever scope i set. I am missing something here or Magento just don’t have ability to setup obscure field fixture out of the box?