本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::expects方法的具体用法?PHP WriteInterface::expects怎么用?PHP WriteInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\WriteInterface
的用法示例。
在下文中一共展示了WriteInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
* Clear state file
*/
protected function tearDown()
{
$this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->writeInterface);
$this->writeInterface->expects($this->any())->method('openFile')->willReturnSelf($this->absolutePath);
$this->state->clearState();
}
示例2: 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->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
$this->materializationStrategyFactory->expects($this->once())->method('create')->with($this->getAsset())->will($this->returnValue($materializationStrategy));
$materializationStrategy->expects($this->once())->method('publishFile')->with($this->rootDirWrite, $this->staticDirWrite, 'some/file.ext', 'some/file.ext')->will($this->returnValue(true));
$this->assertTrue($this->object->publish($this->getAsset()));
}
示例3: testMergeMtimeUnchanged
public function testMergeMtimeUnchanged()
{
$this->targetDir->expects($this->once())->method('isExist')->with('merged/result.txt.dat')->will($this->returnValue(true));
$this->targetDir->expects($this->once())->method('readFile')->with('merged/result.txt.dat')->will($this->returnValue('11'));
$assets = $this->getAssetsToMerge();
$this->mergerMock->expects($this->never())->method('merge');
$this->targetDir->expects($this->never())->method('writeFile');
$this->checksum->merge($assets, $this->resultAsset);
}
示例4: setUp
protected function setUp()
{
$this->stream = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\File\\WriteInterface');
$this->dir = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
$this->dir->expects($this->any())->method('openFile')->with(self::DEBUG_FILE, 'a')->will($this->returnValue($this->stream));
$filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
$filesystem->expects($this->any())->method('getDirectoryWrite')->will($this->returnValue($this->dir));
$this->object = new File($filesystem, self::DEBUG_FILE);
}
示例5: testMergeCss
public function testMergeCss()
{
$this->resultAsset->expects($this->exactly(3))->method('getPath')->will($this->returnValue('foo/result'));
$this->resultAsset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
$assets = $this->prepareAssetsToMerge(['one', 'two']);
$this->cssUrlResolver->expects($this->exactly(2))->method('relocateRelativeUrls')->will($this->onConsecutiveCalls('1', '2'));
$this->cssUrlResolver->expects($this->once())->method('aggregateImportDirectives')->with('12')->will($this->returnValue('1020'));
$this->writeDir->expects($this->once())->method('writeFile')->with('foo/result', '1020');
$this->object->merge($assets, $this->resultAsset);
}
示例6: testCreateRequireJsAssetDevMode
public function testCreateRequireJsAssetDevMode()
{
$this->config->expects($this->once())->method('getConfigFileRelativePath')->will($this->returnValue('requirejs/file.js'));
$this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
$this->assetRepo->expects($this->once())->method('createArbitrary')->with('requirejs/file.js', '')->will($this->returnValue($this->asset));
$this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
$this->dir->expects($this->never())->method('isExist');
$data = 'requirejs config data';
$this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data));
$this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data);
$this->assertSame($this->asset, $this->object->createRequireJsConfigAsset());
}
示例7: testBeforeSave
public function testBeforeSave()
{
$value = 'filename.jpg';
$tmpMediaPath = 'tmp/design/file/' . $value;
$this->fileBackend->setScope('store');
$this->fileBackend->setScopeId(1);
$this->fileBackend->setValue([['url' => 'http://magento2.com/pub/media/tmp/image/' . $value, 'file' => $value, 'size' => 234234]]);
$this->fileBackend->setFieldConfig(['upload_dir' => ['value' => 'value', 'config' => 'system/filesystem/media']]);
$this->mediaDirectory->expects($this->once())->method('copyFile')->with($tmpMediaPath, '/' . $value)->willReturn(true);
$this->mediaDirectory->expects($this->once())->method('delete')->with($tmpMediaPath);
$this->fileBackend->beforeSave();
$this->assertEquals('filename.jpg', $this->fileBackend->getValue());
}
示例8: testBeforeSave
public function testBeforeSave()
{
$value = 'filename.jpg';
$tmpMediaPath = 'tmp/image/' . $value;
$this->imageBackend->setScope('store');
$this->imageBackend->setScopeId(1);
$this->imageBackend->setValue([['url' => 'http://magento2.com/pub/media/tmp/image/' . $value, 'file' => $value, 'size' => 234234]]);
$this->imageConfig->expects($this->exactly(2))->method('getTmpMediaPath')->with($value)->willReturn($tmpMediaPath);
$this->mediaDirectory->expects($this->once())->method('copyFile')->with($tmpMediaPath, 'image/store/1/' . $value)->willReturn(true);
$this->mediaDirectory->expects($this->once())->method('delete')->with($tmpMediaPath);
$this->imageBackend->beforeSave();
$this->assertEquals('store/1/filename.jpg', $this->imageBackend->getValue());
}
示例9: testClearBundleJsPool
public function testClearBundleJsPool()
{
$context = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File\\FallbackContext')->disableOriginalConstructor()->getMock();
$this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->willReturn($this->dir);
$this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($context);
$context->expects($this->once())->method('getPath')->willReturn('/path/to/directory');
$this->dir->expects($this->once())->method('delete')->with('/path/to/directory/' . \Magento\Framework\RequireJs\Config::BUNDLE_JS_DIR)->willReturn(true);
$this->assertTrue($this->object->clearBundleJsPool());
}
示例10: testGetDbFileStat
/**
* @param string $dbCode
* @param array $stat
* @param string|null $stateCode
* @param string|array|bool $result
* @dataProvider getDbFileStatDataProvider
*/
public function testGetDbFileStat($dbCode, $stat, $stateCode, $result)
{
$this->configureDirectoryIsFileIsReadableMethods($dbCode, true, true);
$dbPath = $this->getDbPathNonAbsolute($dbCode);
if ($dbPath) {
$this->directory->expects($this->once())->method('stat')->with($dbPath)->willReturn($stat);
}
$this->assertEquals($result, $this->database->getDbFileStat($dbCode, $stateCode));
}
示例11: testOutput
/**
* @covers \Magento\Backup\Model\Backup::output
* @param bool $isFile
* @param string $result
* @dataProvider outputDataProvider
*/
public function testOutput($isFile, $result)
{
$path = '/path/to';
$time = 1;
$name = 'test';
$type = 'db';
$extension = 'sql';
$relativePath = '/path/to/1_db_test.sql';
$contents = 'test_result';
$this->directoryMock->expects($this->atLeastOnce())->method('isFile')->with($relativePath)->willReturn($isFile);
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($relativePath)->willReturn($relativePath);
$this->directoryMock->expects($this->any())->method('readFile')->with($relativePath)->willReturn($contents);
$this->dataHelperMock->expects($this->any())->method('getExtensionByType')->with($type)->willReturn($extension);
$this->backupModel->setPath($path);
$this->backupModel->setName($name);
$this->backupModel->setTime($time);
$this->assertEquals($result, $this->backupModel->output());
}
示例12: testSaveFile
public function testSaveFile()
{
$imageProcessor = $this->getMockBuilder('Magento\\Framework\\Image')->disableOriginalConstructor()->getMock();
$this->image->setImageProcessor($imageProcessor);
$this->coreFileHelper->expects($this->once())->method('saveFile')->will($this->returnValue(true));
$absolutePath = dirname(dirname(__DIR__)) . '/_files/catalog/product/somefile.png';
$this->mediaDirectory->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($absolutePath));
$this->image->saveFile();
}
示例13: testSaveToTmp
public function testSaveToTmp()
{
$path = 'design/header/logo_src';
$fieldCode = 'header_logo_src';
$metadata = [$fieldCode => ['path' => $path, 'backend_model' => 'Magento\\Theme\\Model\\Design\\Backend\\File']];
$this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store);
$this->store->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_MEDIA)->willReturn('http://magento2.com/pub/media/');
$this->directoryWrite->expects($this->once())->method('getAbsolutePath')->with('tmp/' . FileProcessor::FILE_DIR)->willReturn('absolute/path/to/tmp/media');
$this->metadataProvider->expects($this->once())->method('get')->willReturn($metadata);
$this->backendModelFactory->expects($this->once())->method('createByPath')->with($path)->willReturn($this->backendModel);
$this->uploaderFactory->expects($this->once())->method('create')->with(['fileId' => $fieldCode])->willReturn($this->uploader);
$this->uploader->expects($this->once())->method('setAllowRenameFiles')->with(true);
$this->uploader->expects($this->once())->method('setFilesDispersion')->with(false);
$this->backendModel->expects($this->once())->method('getAllowedExtensions')->willReturn(['png', 'jpg']);
$this->uploader->expects($this->once())->method('setAllowedExtensions')->with(['png', 'jpg']);
$this->uploader->expects($this->once())->method('addValidateCallback')->with('size', $this->backendModel, 'validateMaxSize');
$this->uploader->expects($this->once())->method('save')->with('absolute/path/to/tmp/media')->willReturn(['file' => 'file.jpg', 'size' => '234234']);
$this->assertEquals(['file' => 'file.jpg', 'size' => '234234', 'url' => 'http://magento2.com/pub/media/tmp/' . FileProcessor::FILE_DIR . '/file.jpg'], $this->fileProcessor->saveToTmp($fieldCode));
}
示例14: testGenerateLessFileTree
public function testGenerateLessFileTree()
{
$lessDirectory = 'path/to/less';
$expectedContent = 'updated content';
$expectedRelativePath = 'some/file.less';
$expectedPath = $lessDirectory . '/some/file.less';
$asset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
$chain = $this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false);
$this->config->expects($this->any())->method('getLessDirectory')->willReturn($lessDirectory);
$this->tmpDirectory->expects($this->once())->method('isExist')->willReturn(true);
$this->magentoImport->expects($this->once())->method('process')->with($chain);
$this->import->expects($this->once())->method('process')->with($chain);
$this->relatedGenerator->expects($this->once())->method('generate')->with($this->import);
$asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css'));
$chain->expects($this->once())->method('getContent')->willReturn($expectedContent);
$chain->expects($this->once())->method('getAsset')->willReturn($asset);
$this->temporaryFile->expects($this->once())->method('createFile')->with($expectedRelativePath, $expectedContent)->willReturn($expectedPath);
$this->assertSame($expectedPath, $this->object->generateFileTree($chain));
}
示例15: testGetFile
/**
* @param string $origFile
* @param string $origPath
* @param string $origContent
* @param bool $isMaterialization
* @param bool $isExist
*
* @dataProvider getFileDataProvider
*/
public function testGetFile($origFile, $origPath, $origContent, $isMaterialization, $isExist)
{
$filePath = 'some/file.ext';
$read = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
$read->expects($this->at(0))->method('readFile')->with($origPath)->willReturn($origContent);
$this->readFactory->expects($this->atLeastOnce())->method('create')->willReturn($read);
$this->viewFileResolution->expects($this->once())
->method('getFile')
->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')
->willReturn($origFile);
$this->preProcessorPool->expects($this->once())
->method('process')
->with($this->chain);
$this->staticDirRead->expects($this->any())
->method('isExist')
->willReturn($isExist);
if ($isMaterialization || !$isExist) {
$this->chain
->expects($this->once())
->method('isChanged')
->willReturn(true);
$this->chain
->expects($this->once())
->method('getContent')
->willReturn('processed');
$this->chain
->expects($this->once())
->method('getTargetAssetPath')
->willReturn($filePath);
$this->varDir->expects($this->once())
->method('writeFile')
->with('view_preprocessed/source/some/file.ext', 'processed');
$this->varDir->expects($this->once())
->method('getAbsolutePath')
->willReturn('var');
$read->expects($this->once())
->method('getAbsolutePath')
->with('view_preprocessed/source/some/file.ext')
->willReturn('result');
} else {
$this->varDir->expects($this->never())->method('writeFile');
$read->expects($this->at(1))
->method('getAbsolutePath')
->with('file.ext')
->willReturn('result');
}
$this->assertSame('result', $this->object->getFile($this->getAsset()));
}