@@ -23,16 +23,14 @@ class CompiledTest extends \PHPUnit_Framework_TestCase
2323 protected $ config ;
2424
2525 /**
26- * Definition list
27- *
28- * @var \Magento\Framework\ObjectManager\DefinitionInterface | \PHPUnit_Framework_MockObject_MockObject
26+ * @var Compiled
2927 */
30- protected $ definitions ;
28+ protected $ factory ;
3129
3230 /**
33- * @var Compiled
31+ * @var array
3432 */
35- protected $ factory ;
33+ private $ sharedInstances ;
3634
3735 public function setUp ()
3836 {
@@ -44,36 +42,29 @@ public function setUp()
4442 ->setMethods ([])
4543 ->getMock ();
4644
47- $ this ->definitions = $ this ->getMockBuilder ('Magento\Framework\ObjectManager\DefinitionInterface ' )
48- ->setMethods ([])
49- ->getMock ();
50-
51- $ this ->factory = new Compiled ($ this ->config , $ this ->objectManager , $ this ->definitions , []);
45+ $ this ->sharedInstances = [];
46+ $ this ->factory = new Compiled ($ this ->config , $ this ->sharedInstances , []);
47+ $ this ->factory ->setObjectManager ($ this ->objectManager );
5248 }
5349
5450 public function testCreateSimple ()
5551 {
5652 $ expectedConfig = $ this ->getSimpleConfig ();
5753
5854 $ requestedType = 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\SimpleClassTesting ' ;
55+ $ sharedType = 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencySharedTesting ' ;
56+ $ nonSharedType = 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencyTesting ' ;
5957
60- $ this ->config ->expects ($ this ->once ())
61- ->method ('getInstanceType ' )
62- ->with ($ requestedType )
63- ->willReturn ($ requestedType );
64- $ this ->config ->expects ($ this ->once ())
58+ $ this ->config ->expects ($ this ->any ())
6559 ->method ('getArguments ' )
66- ->with ($ requestedType )
67- ->willReturn ($ expectedConfig );
68-
69- $ this ->objectManager ->expects ($ this ->once ())
70- ->method ('create ' )
71- ->with ('Dependency\StdClass ' )
72- ->willReturn (new \StdClass );
73- $ this ->objectManager ->expects ($ this ->once ())
74- ->method ('get ' )
75- ->with ('Dependency\Shared\StdClass ' )
76- ->willReturn (new \StdClass );
60+ ->willReturnMap (
61+ [
62+ [$ requestedType , $ expectedConfig ],
63+ [$ sharedType , null ],
64+ [$ nonSharedType , null ]
65+ ]
66+ );
67+
7768 $ this ->factory ->setArguments (
7869 [
7970 'globalValue ' => 'GLOBAL_ARGUMENT ' ,
@@ -87,8 +78,8 @@ public function testCreateSimple()
8778 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\SimpleClassTesting ' ,
8879 $ result
8980 );
90- $ this ->assertInstanceOf (' StdClass ' , $ result ->getSharedDependency ());
91- $ this ->assertInstanceOf (' StdClass ' , $ result ->getNonSharedDependency ());
81+ $ this ->assertInstanceOf ($ sharedType , $ result ->getSharedDependency ());
82+ $ this ->assertInstanceOf ($ nonSharedType , $ result ->getNonSharedDependency ());
9283 $ this ->assertEquals ('value ' , $ result ->getValue ());
9384 $ this ->assertEquals (['default_value1 ' , 'default_value2 ' ], $ result ->getValueArray ());
9485 $ this ->assertEquals ('GLOBAL_ARGUMENT ' , $ result ->getGlobalValue ());
@@ -100,24 +91,19 @@ public function testCreateSimpleConfiguredArguments()
10091 $ expectedConfig = $ this ->getSimpleNestedConfig ();
10192
10293 $ requestedType = 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\SimpleClassTesting ' ;
94+ $ sharedType = 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencySharedTesting ' ;
95+ $ nonSharedType = 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencyTesting ' ;
10396
104- $ this ->config ->expects ($ this ->once ())
105- ->method ('getInstanceType ' )
106- ->with ($ requestedType )
107- ->willReturn ($ requestedType );
108- $ this ->config ->expects ($ this ->once ())
97+ $ this ->config ->expects ($ this ->any ())
10998 ->method ('getArguments ' )
110- ->with ($ requestedType )
111- ->willReturn ($ expectedConfig );
112-
113- $ this ->objectManager ->expects ($ this ->exactly (2 ))
114- ->method ('create ' )
115- ->with ('Dependency\StdClass ' )
116- ->willReturn (new \StdClass );
117- $ this ->objectManager ->expects ($ this ->exactly (2 ))
118- ->method ('get ' )
119- ->with ('Dependency\Shared\StdClass ' )
120- ->willReturn (new \StdClass );
99+ ->willReturnMap (
100+ [
101+ [$ requestedType , $ expectedConfig ],
102+ [$ sharedType , null ],
103+ [$ nonSharedType , null ]
104+ ]
105+ );
106+
121107 $ this ->factory ->setArguments (
122108 [
123109 'array_global_existing_argument ' => 'GLOBAL_ARGUMENT ' ,
@@ -132,16 +118,16 @@ public function testCreateSimpleConfiguredArguments()
132118 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\SimpleClassTesting ' ,
133119 $ result
134120 );
135- $ this ->assertInstanceOf (' StdClass ' , $ result ->getSharedDependency ());
136- $ this ->assertInstanceOf (' StdClass ' , $ result ->getNonSharedDependency ());
121+ $ this ->assertInstanceOf ($ sharedType , $ result ->getSharedDependency ());
122+ $ this ->assertInstanceOf ($ nonSharedType , $ result ->getNonSharedDependency ());
137123 $ this ->assertEquals ('value ' , $ result ->getValue ());
138124 $ this ->assertEquals (
139125 [
140126 'array_value ' => 'value ' ,
141- 'array_configured_instance ' => new \ StdClass ,
127+ 'array_configured_instance ' => new $ sharedType ,
142128 'array_configured_array ' => [
143129 'array_array_value ' => 'value ' ,
144- 'array_array_configured_instance ' => new \ StdClass ,
130+ 'array_array_configured_instance ' => new $ nonSharedType ,
145131 ],
146132 'array_global_argument ' => null ,
147133 'array_global_existing_argument ' => 'GLOBAL_ARGUMENT ' ,
@@ -162,10 +148,10 @@ private function getSimpleConfig()
162148 {
163149 return [
164150 'nonSharedDependency ' => [
165- '_ins_ ' => 'Dependency\StdClass ' ,
151+ '_ins_ ' => 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencyTesting ' ,
166152 ],
167153 'sharedDependency ' => [
168- '_i_ ' => 'Dependency\Shared\StdClass ' ,
154+ '_i_ ' => 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencySharedTesting ' ,
169155 ],
170156 'value ' => [
171157 '_v_ ' => 'value ' ,
@@ -192,10 +178,10 @@ private function getSimpleNestedConfig()
192178 {
193179 return [
194180 'nonSharedDependency ' => [
195- '_ins_ ' => 'Dependency\StdClass ' ,
181+ '_ins_ ' => 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencyTesting ' ,
196182 ],
197183 'sharedDependency ' => [
198- '_i_ ' => 'Dependency\Shared\StdClass ' ,
184+ '_i_ ' => 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencySharedTesting ' ,
199185 ],
200186 'value ' => [
201187 '_v_ ' => 'value ' ,
@@ -204,12 +190,12 @@ private function getSimpleNestedConfig()
204190 '_vac_ ' => [
205191 'array_value ' => 'value ' ,
206192 'array_configured_instance ' => [
207- '_i_ ' => 'Dependency\Shared\StdClass ' ,
193+ '_i_ ' => 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencySharedTesting ' ,
208194 ],
209195 'array_configured_array ' => [
210196 'array_array_value ' => 'value ' ,
211197 'array_array_configured_instance ' => [
212- '_ins_ ' => 'Dependency\StdClass ' ,
198+ '_ins_ ' => 'Magento\Framework\ObjectManager\Factory\Fixture\Compiled\DependencyTesting ' ,
213199 ],
214200 ],
215201 'array_global_argument ' => [
0 commit comments