35 $this->registrar = $this->getMockForAbstractClass(
36 \
Magento\Framework\Component\ComponentRegistrarInterface::class
38 $this->readFactory = $this->createMock(\
Magento\Framework\
Filesystem\Directory\ReadFactory::class);
39 $this->dir = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\ReadInterface::class);
40 $this->dir->expects($this->any())
41 ->method(
'getAbsolutePath')
42 ->willReturnArgument(0);
43 $this->
object =
new DirSearch($this->registrar, $this->readFactory);
48 $componentType =
'component_type';
49 $this->registrar->expects($this->exactly(2))
51 ->with($componentType)
53 $this->readFactory->expects($this->never())
55 $this->assertSame([], $this->object->collectFiles($componentType,
'*/file.xml'));
56 $this->assertSame([], $this->object->collectFilesWithContext($componentType,
'*/file.xml'));
61 $componentType =
'component_type';
62 $componentPaths = [
'component1' =>
'path1',
'component2' =>
'path2'];
64 $this->registrar->expects($this->once())
66 ->with($componentType)
67 ->willReturn($componentPaths);
68 $this->readFactory->expects($this->exactly(2))
74 $this->dir->method(
'search')
76 ->willReturnOnConsecutiveCalls([
'one/file.xml'], [
'two/file.xml']);
77 $expected = [
'one/file.xml',
'two/file.xml'];
78 $this->assertSame($expected, $this->object->collectFiles($componentType,
$pattern));
81 public function testCollectFilesWithContext()
83 $componentType =
'component_type';
84 $componentPaths = [
'component1' =>
'path1',
'component2' =>
'path2'];
86 $this->registrar->expects($this->once())
88 ->with($componentType)
89 ->willReturn($componentPaths);
90 $this->readFactory->expects($this->exactly(2))
96 $this->dir->method(
'search')
98 ->willReturnOnConsecutiveCalls([
'one/file.xml'], [
'two/file.xml']);
99 $actualFiles = $this->
object->collectFilesWithContext($componentType,
$pattern);
100 $this->assertNotEmpty($actualFiles);
102 foreach ($actualFiles as $file) {
103 $this->assertInstanceOf(\
Magento\Framework\Component\ComponentFile::class, $file);
104 $this->assertSame($componentType, $file->getComponentType());
106 $this->assertCount(2, $actualFiles);
107 $this->assertSame(
'component1', $actualFiles[0]->getComponentName());
108 $this->assertSame(
'one/file.xml', $actualFiles[0]->getFullPath());
109 $this->assertSame(
'component2', $actualFiles[1]->getComponentName());
110 $this->assertSame(
'two/file.xml', $actualFiles[1]->getFullPath());
testCollectFilesNothingFound()