Skip to content

Commit 7929585

Browse files
committed
Fix Module\ModuleList\LoaderTest and add assertions for new Resolver functionality
1 parent a108dab commit 7929585

File tree

1 file changed

+41
-16
lines changed
  • lib/internal/Magento/Framework/Module/Test/Unit/ModuleList

1 file changed

+41
-16
lines changed

lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/LoaderTest.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ class LoaderTest extends \PHPUnit_Framework_TestCase
4040
*/
4141
private $parser;
4242

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+
4358
protected function setUp()
4459
{
4560
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
@@ -50,34 +65,44 @@ protected function setUp()
5065
->willReturn($this->dir);
5166
$this->converter = $this->getMock('Magento\Framework\Module\Declaration\Converter\Dom', [], [], '', false);
5267
$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);
5372
}
5473

5574
public function testLoad()
5675
{
57-
$fixture = [
76+
$fixtures = [
5877
'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
6283
];
6384
$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']);
6486
$this->dir->expects($this->exactly(3))->method('readFile')->will($this->returnValueMap([
6587
['a', null, null, self::$sampleXml],
6688
['b', null, null, self::$sampleXml],
6789
['c', null, null, self::$sampleXml],
6890
]));
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+
}
7399
$this->parser->expects($this->atLeastOnce())->method('loadXML');
74100
$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+
}
81106
}
82107

83108
/**
@@ -97,7 +122,7 @@ public function testLoadCircular()
97122
]));
98123
$this->converter->expects($this->at(0))->method('convert')->willReturn(['a' => $fixture['a']]);
99124
$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();
102127
}
103128
}

0 commit comments

Comments
 (0)