本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\ReadInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ReadInterface::expects方法的具体用法?PHP ReadInterface::expects怎么用?PHP ReadInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\ReadInterface
的用法示例。
在下文中一共展示了ReadInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetConfig
public function testGetConfig()
{
$this->baseDir->expects($this->any())->method('getRelativePath')->will($this->returnCallback(function ($path) {
return 'relative/' . $path;
}));
$this->baseDir->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) {
return $file . ' content';
}));
$fileOne = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false);
$fileOne->expects($this->once())->method('getFilename')->will($this->returnValue('file_one.js'));
$fileOne->expects($this->once())->method('getModule')->will($this->returnValue('Module_One'));
$fileTwo = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false);
$fileTwo->expects($this->once())->method('getFilename')->will($this->returnValue('file_two.js'));
$theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface');
$this->design->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme));
$this->fileSource->expects($this->once())->method('getFiles')->with($theme, Config::CONFIG_FILE_NAME)->will($this->returnValue([$fileOne, $fileTwo]));
$expected = <<<expected
(function(require){
require.config({"baseUrl":""});
(function() {
relative/file_one.js content
require.config(config);
})();
(function() {
relative/file_two.js content
require.config(config);
})();
})(require);
expected;
$actual = $this->object->getConfig();
$this->assertStringMatchesFormat($expected, $actual);
}
示例2: testLoadData
/**
* @test
* @return void
*/
public function testLoadData()
{
$fileContent = 'content file';
$media = ['preview_image' => 'preview.jpg'];
$themeTitle = 'Theme title';
$themeConfigFile = 'theme.xml';
$themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock();
$theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
$parentTheme = ['parentThemeCode'];
$parentThemePath = 'frontend/parent/theme';
$themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false);
$themePackage->expects($this->any())->method('getArea')->will($this->returnValue('frontend'));
$themePackage->expects($this->any())->method('getVendor')->will($this->returnValue('theme'));
$themePackage->expects($this->any())->method('getName')->will($this->returnValue('code'));
$this->themePackageList->expects($this->once())->method('getThemes')->will($this->returnValue([$themePackage]));
$this->directory->expects($this->once())->method('isExist')->with($themeConfigFile)->willReturn(true);
$this->directory->expects($this->once())->method('readFile')->with($themeConfigFile)->willReturn($fileContent);
$this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig);
$this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme);
$themeConfig->expects($this->once())->method('getMedia')->willReturn($media);
$themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme);
$themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
$theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme/code', 'code' => 'theme/code', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => 'theme/parentThemeCode'])->willReturnSelf();
$theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath);
$theme->expects($this->once())->method('getArea')->willReturn('frontend');
$this->assertInstanceOf(get_class($this->model), $this->model->loadData());
}
示例3: testLoadData
/**
* @param string $area
* @param bool $forceReload
* @param array $cachedData
* @dataProvider dataProviderForTestLoadData
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function testLoadData($area, $forceReload, $cachedData)
{
$this->expectsSetConfig('themeId');
$this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('load')->will($this->returnValue(serialize($cachedData)));
if (!$forceReload && $cachedData !== false) {
$this->translate->loadData($area, $forceReload);
$this->assertEquals($cachedData, $this->translate->getData());
return;
}
$this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true));
// _loadModuleTranslation()
$this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name']));
$moduleData = ['module original' => 'module translated', 'module theme' => 'module-theme original translated', 'module pack' => 'module-pack original translated', 'module db' => 'module-db original translated'];
$this->modulesReader->expects($this->any())->method('getModuleDir')->will($this->returnValue('/app/module'));
$themeData = ['theme original' => 'theme translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'theme-pack translated overwrite', 'module db' => 'theme-db translated overwrite'];
$this->csvParser->expects($this->any())->method('getDataPairs')->will($this->returnValueMap([['/app/module/en_US.csv', 0, 1, $moduleData], ['/app/module/en_GB.csv', 0, 1, $moduleData], ['/theme.csv', 0, 1, $themeData]]));
// _loadThemeTranslation()
$this->viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue('/theme.csv'));
// _loadPackTranslation
$packData = ['pack original' => 'pack translated', 'module pack' => 'pack translated overwrite', 'module db' => 'pack-db translated overwrite'];
$this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue($packData));
// _loadDbTranslation()
$dbData = ['db original' => 'db translated', 'module db' => 'db translated overwrite'];
$this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData));
$this->cache->expects($this->exactly(1))->method('save');
$this->translate->loadData($area, $forceReload);
$expected = ['module original' => 'module translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'pack translated overwrite', 'module db' => 'db translated overwrite', 'theme original' => 'theme translated', 'pack original' => 'pack translated', 'db original' => 'db translated'];
$this->assertEquals($expected, $this->translate->getData());
}
示例4: setUp
protected function setUp()
{
$this->registrar = $this->getMockForAbstractClass('\\Magento\\Framework\\Component\\ComponentRegistrarInterface');
$this->readFactory = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false);
$this->dir = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
$this->dir->expects($this->any())->method('getAbsolutePath')->willReturnArgument(0);
$this->object = new DirSearch($this->registrar, $this->readFactory);
}
示例5: testPublish
public function testPublish()
{
$this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
$this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
$this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
$this->rootDirWrite->expects($this->once())->method('copyFile')->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)->will($this->returnValue(true));
$this->assertTrue($this->object->publish($this->getAsset()));
}
示例6: testPublish
public function testPublish()
{
$this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
$materializationStrategy = $this->getMock('Magento\\Framework\\App\\View\\Asset\\MaterializationStrategy\\StrategyInterface', [], [], '', false);
$this->materializationStrategyFactory->expects($this->once())->method('create')->with($this->getAsset())->will($this->returnValue($materializationStrategy));
$materializationStrategy->expects($this->once())->method('publishFile')->with($this->sourceDirWrite, $this->staticDirWrite, 'file.ext', 'some/file.ext')->will($this->returnValue(true));
$this->assertTrue($this->object->publish($this->getAsset()));
}
示例7: testBasePackageInfo
public function testBasePackageInfo()
{
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
$jsonData = json_encode([BasePackageInfo::COMPOSER_KEY_EXTRA => [BasePackageInfo::COMPOSER_KEY_MAP => [[__FILE__, __FILE__], [__DIR__, __DIR__]]]]);
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
$expectedList = [__FILE__, __DIR__];
$actualList = $this->basePackageInfo->getPaths();
$this->assertEquals($expectedList, $actualList);
}
示例8: prepareAttemptToMinifyMock
protected function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true, $originalExists = true)
{
$this->asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/admin.js'));
$this->asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/admin.js'));
if ($rootDirExpectations) {
$this->rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/admin.min.js')->will($this->returnValue('test/admin.min.js'));
$this->rootDir->expects($this->once())->method('isExist')->with('test/admin.min.js')->will($this->returnValue(false));
}
$this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/'));
$this->staticViewDir->expects($this->exactly(2 - intval($originalExists)))->method('isExist')->will($this->returnValue($fileExists));
}
示例9: getAssetsToMerge
/**
* Create mocks of assets to merge, as well as a few related necessary mocks
*
* @return array
*/
private function getAssetsToMerge()
{
$one = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
$one->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/one.txt'));
$two = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
$two->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/two.txt'));
$this->sourceDir->expects($this->exactly(2))->method('getRelativePath')->will($this->onConsecutiveCalls('file/one.txt', 'file/two.txt'));
$this->sourceDir->expects($this->exactly(2))->method('stat')->will($this->returnValue(['mtime' => '1']));
$this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('merged/result.txt'));
return [$one, $two];
}
示例10: testCopyQuoteToOrder
public function testCopyQuoteToOrder()
{
$optionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface')->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
$quotePath = '/quote/path/path/uploaded.file';
$orderPath = '/order/path/path/uploaded.file';
$optionMock->expects($this->any())->method('getValue')->will($this->returnValue(['quote_path' => $quotePath, 'order_path' => $orderPath]));
$this->rootDirectory->expects($this->any())->method('isFile')->with($this->equalTo($quotePath))->will($this->returnValue(true));
$this->rootDirectory->expects($this->any())->method('isReadable')->with($this->equalTo($quotePath))->will($this->returnValue(true));
$this->rootDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValue('/file.path'));
$this->coreFileStorageDatabase->expects($this->any())->method('copyFile')->will($this->returnValue('true'));
$fileObject = $this->getFileObject();
$fileObject->setData('configuration_item_option', $optionMock);
$this->assertInstanceOf('Magento\\Catalog\\Model\\Product\\Option\\Type\\File', $fileObject->copyQuoteToOrder());
}
示例11: setUp
protected function setUp()
{
$this->tmpDirectory = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
$this->rootDirectory = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
$this->rootDirectory->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
$this->rootDirectory->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) {
return "content of '{$file}'";
}));
$filesystem = $this->getMock('\\Magento\\Framework\\App\\Filesystem', array(), array(), '', false);
$filesystem->expects($this->once())->method('getDirectoryWrite')->with(\Magento\Framework\App\Filesystem::VAR_DIR)->will($this->returnValue($this->tmpDirectory));
$this->assetRepo = $this->getMock('\\Magento\\Framework\\View\\Asset\\Repository', array(), array(), '', false);
$this->magentoImport = $this->getMock('\\Magento\\Framework\\Less\\PreProcessor\\Instruction\\MagentoImport', array(), array(), '', false);
$this->import = $this->getMock('\\Magento\\Framework\\Less\\PreProcessor\\Instruction\\Import', array(), array(), '', false);
$this->object = new \Magento\Framework\Less\FileGenerator($filesystem, $this->assetRepo, $this->magentoImport, $this->import);
}
示例12: testGetData
/**
* @return void
*/
public function testGetData()
{
$themePath = 'blank';
$areaCode = 'adminhtml';
$files = [['path1'], ['path2']];
$relativePathMap = [['path1' => 'relativePath1'], ['path2' => 'relativePath2']];
$contentsMap = [['relativePath1' => 'content1$.mage.__("hello1")content1'], ['relativePath2' => 'content2$.mage.__("hello2")content2']];
$patterns = ['~\\$\\.mage\\.__\\([\'|\\"](.+?)[\'|\\"]\\)~'];
$this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
$this->filesUtilityMock->expects($this->once())->method('getJsFiles')->with($areaCode, $themePath)->willReturn($files);
$this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnMap($relativePathMap);
$this->rootDirectoryMock->expects($this->any())->method('readFile')->willReturnMap($contentsMap);
$this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns);
$this->assertEquals([], $this->model->getData($themePath));
}
示例13: setUp
/**
* Initialize testable object
*/
protected function setUp()
{
$this->htmlDirectoryMock = $this->getMockBuilder(Filesystem\Directory\WriteInterface::class)->getMockForAbstractClass();
$this->appDirectoryMock = $this->getMockBuilder(ReadInterface::class)->getMockForAbstractClass();
$this->rootDirectoryMock = $this->getMockBuilder(ReadInterface::class)->getMockForAbstractClass();
$this->filesystemMock = $this->getMockBuilder(Filesystem::class)->disableOriginalConstructor()->getMock();
$this->readFactoryMock = $this->getMockBuilder(Filesystem\Directory\ReadFactory::class)->disableOriginalConstructor()->getMock();
$this->filesystemMock->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::TEMPLATE_MINIFICATION_DIR)->willReturn($this->htmlDirectoryMock);
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::ROOT, DriverPool::FILE)->willReturn($this->rootDirectoryMock);
$this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnCallback(function ($value) {
return ltrim($value, '/');
});
$this->readFactoryMock->expects($this->any())->method('create')->willReturn($this->appDirectoryMock);
$this->object = (new ObjectManager($this))->getObject(Minifier::class, ['filesystem' => $this->filesystemMock, 'readFactory' => $this->readFactoryMock]);
}
示例14: testGetFilesMultiple
public function testGetFilesMultiple()
{
$dirPath = '/Magento_Customer/css/';
$themePath = '/opt/magento2/app/design/frontend/Magento/blank';
$searchPath = 'css/*.test';
$this->themeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath));
$this->themesDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap([['fileA.test', $dirPath . 'fileA.test'], ['fileB.tst', $dirPath . 'fileB.tst'], ['fileC.test', $dirPath . 'fileC.test']]));
$fileMock = $this->getMockBuilder('Magento\\Framework\\View\\File')->disableOriginalConstructor()->getMock();
// Verifies correct files are searched for
$this->themesDirectoryMock->expects($this->once())->method('search')->with($themePath . '/' . $searchPath)->will($this->returnValue(['fileA.test', 'fileC.test']));
// Verifies Magento_Customer was correctly produced from directory path
$this->fileFactoryMock->expects($this->any())->method('create')->with($this->isType('string'), null, $this->equalTo($this->themeMock))->will($this->returnValue($fileMock));
$theme = new Theme($this->filesystemMock, $this->fileFactoryMock);
// Only two files should be in array, which were returned from search
$this->assertEquals([$fileMock, $fileMock], $theme->getFiles($this->themeMock, 'css/*.test'));
}
示例15: testGetFaviconFile
/**
* cover positive case for getFaviconFile and checkIsFile
*/
public function testGetFaviconFile()
{
$scopeConfigValue = 'path';
$urlToMediaDir = 'http://magento.url/pub/media/';
$expectedFile = ImageFavicon::UPLOAD_DIR . '/' . $scopeConfigValue;
$expectedUrl = $urlToMediaDir . $expectedFile;
$this->scopeManager->expects($this->once())->method('getValue')->with('design/head/shortcut_icon', ScopeInterface::SCOPE_STORE)->willReturn($scopeConfigValue);
$this->store->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_MEDIA)->willReturn($urlToMediaDir);
$this->fileStorageDatabase->expects($this->once())->method('checkDbUsage')->willReturn(true);
$this->fileStorageDatabase->expects($this->once())->method('saveFileToFilesystem')->willReturn(true);
$this->mediaDir->expects($this->at(0))->method('isFile')->with($expectedFile)->willReturn(false);
$this->mediaDir->expects($this->at(1))->method('isFile')->with($expectedFile)->willReturn(true);
$results = $this->object->getFaviconFile();
$this->assertEquals($expectedUrl, $results);
$this->assertNotFalse($results);
}