File tree Expand file tree Collapse file tree 2 files changed +66
-1
lines changed
dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Definition
lib/internal/Magento/Framework/ObjectManager/Definition Expand file tree Collapse file tree 2 files changed +66
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2015 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \Framework \ObjectManager \Definition ;
7
+
8
+ class CompiledTest extends \PHPUnit_Framework_TestCase
9
+ {
10
+ public function testGetParametersWithUndefinedDefinition ()
11
+ {
12
+ $ objectManager = new \Magento \TestFramework \Helper \ObjectManager ($ this );
13
+ $ undefinedDefinitionSignature = new \stdClass ();
14
+ $ className = 'undefinedDefinition ' ;
15
+ $ readerMock = $ this ->getMock (
16
+ '\Magento\Framework\Code\Reader\ClassReader ' ,
17
+ ['getConstructor ' ],
18
+ [],
19
+ '' ,
20
+ false
21
+ );
22
+ $ readerMock ->expects ($ this ->once ())
23
+ ->method ('getConstructor ' )
24
+ ->with ($ className )
25
+ ->willReturn ($ undefinedDefinitionSignature );
26
+ $ model = $ objectManager ->getObject (
27
+ 'Magento\Framework\ObjectManager\Definition\CompiledStub ' ,
28
+ [
29
+ 'definitions ' => [[], []],
30
+ 'reader ' => $ readerMock
31
+ ]
32
+ );
33
+ $ this ->assertEquals ($ undefinedDefinitionSignature , $ model ->getParameters ($ className ));
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Stub class for abstract Magento\Framework\ObjectManager\Definition
39
+ */
40
+ class CompiledStub extends Compiled
41
+ {
42
+
43
+ /**
44
+ * Unpack signature
45
+ *
46
+ * @param string $signature
47
+ * @return mixed
48
+ */
49
+ protected function _unpack ($ signature )
50
+ {
51
+ return unserialize ($ signature );
52
+ }
53
+ }
Original file line number Diff line number Diff line change @@ -17,12 +17,19 @@ abstract class Compiled implements \Magento\Framework\ObjectManager\DefinitionIn
17
17
*/
18
18
protected $ _definitions ;
19
19
20
+ /**
21
+ * @var \Magento\Framework\Code\Reader\ClassReader
22
+ */
23
+ protected $ reader ;
24
+
20
25
/**
21
26
* @param array $definitions
27
+ * @param \Magento\Framework\Code\Reader\ClassReader $reader
22
28
*/
23
- public function __construct (array $ definitions )
29
+ public function __construct (array $ definitions, \ Magento \ Framework \ Code \ Reader \ ClassReader $ reader = null )
24
30
{
25
31
list ($ this ->_signatures , $ this ->_definitions ) = $ definitions ;
32
+ $ this ->reader = $ reader ?: new \Magento \Framework \Code \Reader \ClassReader ();
26
33
}
27
34
28
35
/**
@@ -51,6 +58,11 @@ abstract protected function _unpack($signature);
51
58
*/
52
59
public function getParameters ($ className )
53
60
{
61
+ // if the definition isn't found in the list gathered from the compiled file then using reflection to find it
62
+ if (!array_key_exists ($ className , $ this ->_definitions )) {
63
+ return $ this ->reader ->getConstructor ($ className );
64
+ }
65
+
54
66
$ definition = $ this ->_definitions [$ className ];
55
67
if ($ definition !== null ) {
56
68
if (is_string ($ this ->_signatures [$ definition ])) {
You can’t perform that action at this time.
0 commit comments