1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\ObjectManager\Test\Unit\Config;
use Magento\Framework\Serialize\SerializerInterface;
use \Magento\Framework\ObjectManager\Config\Config;
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
private $objectManagerHelper;
protected function setUp()
{
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
}
public function testGetArgumentsEmpty()
{
$config = new Config();
$this->assertSame([], $config->getArguments('An invalid type'));
}
public function testExtendMergeConfiguration()
{
$this->_assertFooTypeArguments(new Config());
}
/**
* A primitive fixture for testing merging arguments
*
* @param Config $config
*/
private function _assertFooTypeArguments(Config $config)
{
$expected = ['argName' => 'argValue'];
$fixture = ['FooType' => ['arguments' => $expected]];
$config->extend($fixture);
$this->assertEquals($expected, $config->getArguments('FooType'));
}
public function testExtendWithCacheMock()
{
$definitions = $this->createMock(\Magento\Framework\ObjectManager\DefinitionInterface::class);
$definitions->expects($this->once())->method('getClasses')->will($this->returnValue(['FooType']));
$cache = $this->createMock(\Magento\Framework\ObjectManager\ConfigCacheInterface::class);
$cache->expects($this->once())->method('get')->will($this->returnValue(false));
$config = new Config(null, $definitions);
$serializerMock = $this->createMock(SerializerInterface::class);
$serializerMock->expects($this->exactly(2))
->method('serialize');
$this->objectManagerHelper->setBackwardCompatibleProperty(
$config,
'serializer',
$serializerMock
);
$config->setCache($cache);
$this->_assertFooTypeArguments($config);
}
public function testGetPreferenceTrimsFirstSlash()
{
$config = new Config();
$this->assertEquals('Some\Class\Name', $config->getPreference('\Some\Class\Name'));
}
public function testExtendIgnoresFirstSlashesOnPreferences()
{
$config = new Config();
$config->extend(['preferences' => ['\Some\Interface' => '\Some\Class']]);
$this->assertEquals('Some\Class', $config->getPreference('Some\Interface'));
$this->assertEquals('Some\Class', $config->getPreference('\Some\Interface'));
}
public function testExtendIgnoresFirstShashesOnVirtualTypes()
{
$config = new Config();
$config->extend(['\SomeVirtualType' => ['type' => '\Some\Class']]);
$this->assertEquals('Some\Class', $config->getInstanceType('SomeVirtualType'));
}
public function testExtendIgnoresFirstShashes()
{
$config = new Config();
$config->extend(['\Some\Class' => ['arguments' => ['someArgument']]]);
$this->assertEquals(['someArgument'], $config->getArguments('Some\Class'));
}
public function testExtendIgnoresFirstShashesForSharing()
{
$config = new Config();
$config->extend(['\Some\Class' => ['shared' => true]]);
$this->assertTrue($config->isShared('Some\Class'));
}
}