b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / vendor / magento / framework / Config / Test / Unit / Data /
Filename/home/a/home/dev2.destoffenstraat.com/vendor/magento/framework/Config/Test/Unit/Data/ScopedTest.php
Size5.66 kb
Permissionrw-r--r--
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified07-Jan-2021 21:08
Last accessed23-Aug-2025 12:53
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Config\Test\Unit\Data;

use Magento\Framework\Config\CacheInterface;
use Magento\Framework\Config\Data\Scoped;
use Magento\Framework\Config\ReaderInterface;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ScopedTest extends TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var Scoped
*/
protected $_model;

/**
* @var MockObject
*/
protected $_readerMock;

/**
* @var MockObject
*/
protected $_configScopeMock;

/**
* @var MockObject
*/
protected $_cacheMock;

/**
* @var SerializerInterface|MockObject
*/
private $serializerMock;

protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->_readerMock = $this->getMockForAbstractClass(ReaderInterface::class);
$this->_configScopeMock = $this->getMockForAbstractClass(ScopeInterface::class);
$this->_cacheMock = $this->getMockForAbstractClass(CacheInterface::class);
$this->serializerMock = $this->getMockForAbstractClass(SerializerInterface::class);

$this->_model = $this->objectManager->getObject(
Scoped::class,
[
'reader' => $this->_readerMock,
'configScope' => $this->_configScopeMock,
'cache' => $this->_cacheMock,
'cacheId' => 'tag',
'serializer' => $this->serializerMock
]
);
}

/**
* @param string $path
* @param mixed $expectedValue
* @param string $default
* @dataProvider getConfigByPathDataProvider
*/
public function testGetConfigByPath($path, $expectedValue, $default)
{
$testData = [
'key_1' => [
'key_1.1' => ['key_1.1.1' => 'value_1.1.1'],
'key_1.2' => ['some' => 'arrayValue'],
],
];
$this->_cacheMock->expects($this->once())
->method('load')
->willReturn(false);
$this->_readerMock->expects($this->once())
->method('read')
->willReturn([]);
$this->_model->merge($testData);
$this->assertEquals($expectedValue, $this->_model->get($path, $default));
}

/**
* @return array
*/
public function getConfigByPathDataProvider()
{
return [
['key_1/key_1.1/key_1.1.1', 'value_1.1.1', 'error'],
['key_1/key_1.2', ['some' => 'arrayValue'], 'error'],
[
'key_1',
['key_1.1' => ['key_1.1.1' => 'value_1.1.1'], 'key_1.2' => ['some' => 'arrayValue']],
'error'
],
['key_1/notExistedKey', 'defaultValue', 'defaultValue']
];
}

public function testGetScopeSwitchingWithNonCachedData()
{
$testValue = ['some' => 'testValue'];
$serializedData = 'serialized data';

/** change current area */
$this->_configScopeMock->expects(
$this->any()
)->method(
'getCurrentScope'
)->willReturn(
'adminhtml'
);

/** set empty cache data */
$this->_cacheMock->expects(
$this->once()
)->method(
'load'
)->with(
'adminhtml::tag'
)->willReturn(
false
);

/** get data from reader */
$this->_readerMock->expects(
$this->once()
)->method(
'read'
)->with(
'adminhtml'
)->willReturn(
$testValue
);

$this->serializerMock->expects($this->once())
->method('serialize')
->with($testValue)
->willReturn($serializedData);

/** test cache saving */
$this->_cacheMock->expects($this->once())
->method('save')
->with($serializedData, 'adminhtml::tag');

/** test config value existence */
$this->assertEquals('testValue', $this->_model->get('some'));

/** test preventing of double config data loading from reader */
$this->assertEquals('testValue', $this->_model->get('some'));
}

public function testGetScopeSwitchingWithCachedData()
{
$testValue = ['some' => 'testValue'];
$serializedData = 'serialized data';

/** change current area */
$this->_configScopeMock->expects(
$this->any()
)->method(
'getCurrentScope'
)->willReturn(
'adminhtml'
);

$this->serializerMock->expects($this->once())
->method('unserialize')
->with($serializedData)
->willReturn($testValue);

/** set cache data */
$this->_cacheMock->expects($this->once())
->method('load')
->with('adminhtml::tag')
->willReturn($serializedData);

/** test preventing of getting data from reader */
$this->_readerMock->expects($this->never())->method('read');

/** test preventing of cache saving */
$this->_cacheMock->expects($this->never())->method('save');

/** test config value existence */
$this->assertEquals('testValue', $this->_model->get('some'));

/** test preventing of double config data loading from reader */
$this->assertEquals('testValue', $this->_model->get('some'));
}
}