@@ -40,6 +40,21 @@ class LoaderTest extends \PHPUnit_Framework_TestCase
40
40
*/
41
41
private $ parser ;
42
42
43
+ /*
44
+ * @var \PHPUnit_Framework_MockObject_MockObject
45
+ */
46
+ private $ resolver ;
47
+
48
+ /*
49
+ * @var \PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ private $ driver ;
52
+
53
+ /**
54
+ * @var \Magento\Framework\Module\ModuleList\Loader
55
+ */
56
+ private $ loader ;
57
+
43
58
protected function setUp ()
44
59
{
45
60
$ this ->filesystem = $ this ->getMock ('Magento\Framework\Filesystem ' , [], [], '' , false );
@@ -50,34 +65,44 @@ protected function setUp()
50
65
->willReturn ($ this ->dir );
51
66
$ this ->converter = $ this ->getMock ('Magento\Framework\Module\Declaration\Converter\Dom ' , [], [], '' , false );
52
67
$ this ->parser = $ this ->getMock ('Magento\Framework\Xml\Parser ' , [], [], '' , false );
68
+ $ this ->parser ->expects ($ this ->once ())->method ('initErrorHandler ' );
69
+ $ this ->resolver = $ this ->getMock ('Magento\Framework\Module\Dir\ResolverInterface ' , [], [], '' , false , false );
70
+ $ this ->driver = $ this ->getMock ('Magento\Framework\Filesystem\DriverInterface ' , [], [], '' , false , false );
71
+ $ this ->loader = new Loader ($ this ->filesystem , $ this ->converter , $ this ->parser , $ this ->resolver , $ this ->driver );
53
72
}
54
73
55
74
public function testLoad ()
56
75
{
57
- $ fixture = [
76
+ $ fixtures = [
58
77
'a ' => ['name ' => 'a ' , 'sequence ' => []], // a is on its own
59
- 'b ' => ['name ' => 'b ' , 'sequence ' => ['c ' ]], // b is after c
60
- 'c ' => ['name ' => 'c ' , 'sequence ' => ['a ' ]], // c is after a
61
- // so expected sequence is a -> c -> b
78
+ 'b ' => ['name ' => 'b ' , 'sequence ' => ['d ' ]], // b is after c
79
+ 'c ' => ['name ' => 'c ' , 'sequence ' => ['e ' ]], // c is after e
80
+ 'd ' => ['name ' => 'd ' , 'sequence ' => ['c ' ]], // d is after c
81
+ 'e ' => ['name ' => 'e ' , 'sequence ' => ['a ' ]], // e is after a
82
+ // so expected sequence is a -> e -> c -> d -> b
62
83
];
63
84
$ this ->dir ->expects ($ this ->once ())->method ('search ' )->willReturn (['a ' , 'b ' , 'c ' ]);
85
+ $ this ->resolver ->expects ($ this ->once ())->method ('getModulePaths ' )->willReturn (['/path/to/d ' , '/path/to/e ' ]);
64
86
$ this ->dir ->expects ($ this ->exactly (3 ))->method ('readFile ' )->will ($ this ->returnValueMap ([
65
87
['a ' , null , null , self ::$ sampleXml ],
66
88
['b ' , null , null , self ::$ sampleXml ],
67
89
['c ' , null , null , self ::$ sampleXml ],
68
90
]));
69
- $ this ->converter ->expects ($ this ->at (0 ))->method ('convert ' )->willReturn (['a ' => $ fixture ['a ' ]]);
70
- $ this ->converter ->expects ($ this ->at (1 ))->method ('convert ' )->willReturn (['b ' => $ fixture ['b ' ]]);
71
- $ this ->converter ->expects ($ this ->at (2 ))->method ('convert ' )->willReturn (['c ' => $ fixture ['c ' ]]);
72
- $ this ->parser ->expects ($ this ->once ())->method ('initErrorHandler ' );
91
+ $ this ->driver ->expects ($ this ->exactly (2 ))->method ('fileGetContents ' )->will ($ this ->returnValueMap ([
92
+ ['/path/to/d ' , null , null , self ::$ sampleXml ],
93
+ ['/path/to/e ' , null , null , self ::$ sampleXml ],
94
+ ]));
95
+ $ index = 0 ;
96
+ foreach ($ fixtures as $ name => $ fixture ) {
97
+ $ this ->converter ->expects ($ this ->at ($ index ++))->method ('convert ' )->willReturn ([$ name => $ fixture ]);
98
+ }
73
99
$ this ->parser ->expects ($ this ->atLeastOnce ())->method ('loadXML ' );
74
100
$ this ->parser ->expects ($ this ->atLeastOnce ())->method ('getDom ' );
75
- $ object = new Loader ($ this ->filesystem , $ this ->converter , $ this ->parser );
76
- $ result = $ object ->load ();
77
- $ this ->assertSame (['a ' , 'c ' , 'b ' ], array_keys ($ result ));
78
- $ this ->assertSame ($ fixture ['a ' ], $ result ['a ' ]);
79
- $ this ->assertSame ($ fixture ['b ' ], $ result ['b ' ]);
80
- $ this ->assertSame ($ fixture ['c ' ], $ result ['c ' ]);
101
+ $ result = $ this ->loader ->load ();
102
+ $ this ->assertSame (['a ' , 'e ' , 'c ' , 'd ' , 'b ' ], array_keys ($ result ));
103
+ foreach ($ fixtures as $ name => $ fixture ) {
104
+ $ this ->assertSame ($ fixture , $ result [$ name ]);
105
+ }
81
106
}
82
107
83
108
/**
@@ -97,7 +122,7 @@ public function testLoadCircular()
97
122
]));
98
123
$ this ->converter ->expects ($ this ->at (0 ))->method ('convert ' )->willReturn (['a ' => $ fixture ['a ' ]]);
99
124
$ this ->converter ->expects ($ this ->at (1 ))->method ('convert ' )->willReturn (['b ' => $ fixture ['b ' ]]);
100
- $ object = new Loader ( $ this ->filesystem , $ this -> converter , $ this ->parser );
101
- $ object ->load ();
125
+ $ this ->resolver -> expects ( $ this ->once ())-> method ( ' getModulePaths ' )-> willReturn ([] );
126
+ $ this -> loader ->load ();
102
127
}
103
128
}
0 commit comments