$locatorMockForAdditionalLoader =
$this->
createMock(FileLocatorInterface::
class);
$locatorMockForAdditionalLoader->
expects($this->
any())->
method('locate'
)->
will($this->
onConsecutiveCalls( ['path/to/file1'
], // Default
['path/to/file1', 'path/to/file2'
], // First is imported
['path/to/file1', 'path/to/file2'
], // Second is imported
['path/to/file1'
], // Exception
['path/to/file1', 'path/to/file2'
] // Exception
));
$fileLoader =
new TestFileLoader($locatorMock);
$fileLoader->
setSupports(false
);
$fileLoader->
setCurrentDir('.'
);
$additionalLoader =
new TestFileLoader($locatorMockForAdditionalLoader);
$additionalLoader->
setCurrentDir('.'
);
$fileLoader->
setResolver($loaderResolver =
new LoaderResolver([$fileLoader,
$additionalLoader]));
// Default case
$this->
assertSame('path/to/file1',
$fileLoader->
import('my_resource'
));
// Check first file is imported if not already loading
$this->
assertSame('path/to/file1',
$fileLoader->
import('my_resource'
));