本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\Write::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Write::expects方法的具体用法?PHP Write::expects怎么用?PHP Write::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\Write
的用法示例。
在下文中一共展示了Write::expects方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGenerateSwatchVariations
public function testGenerateSwatchVariations()
{
$this->mediaDirectoryMock->expects($this->atLeastOnce())->method('getAbsolutePath')->willReturn('attribute/swatch/e/a/earth.png');
$image = $this->getMock('\\Magento\\Framework\\Image', ['resize', 'save', 'keepTransparency', 'constrainOnly', 'keepFrame', 'keepAspectRatio', 'backgroundColor', 'quality'], [], '', false);
$this->imageFactoryMock->expects($this->any())->method('create')->willReturn($image);
$this->generateImageConfig();
$image->expects($this->any())->method('resize')->will($this->returnSelf());
$this->mediaHelperObject->generateSwatchVariations('/e/a/earth.png');
}
示例2: setUp
/**
* Set up
*/
public function setUp()
{
$this->context = $this->getMock('Magento\\Framework\\App\\Helper\\Context', [], [], '', false);
$this->timezone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Timezone', ['date', 'getConfigTimezone', 'diff', 'format'], [], '', false);
$this->varDirectory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['getRelativePath', 'readFile', 'isFile', 'stat'], [], '', false);
$this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false);
$this->varDirectory->expects($this->any())->method('getRelativePath')->willReturn('path');
$this->varDirectory->expects($this->any())->method('readFile')->willReturn('contents');
$this->varDirectory->expects($this->any())->method('isFile')->willReturn(true);
$this->varDirectory->expects($this->any())->method('stat')->willReturn(100);
$this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->varDirectory);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->report = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Helper\\Report', ['context' => $this->context, 'timeZone' => $this->timezone, 'filesystem' => $this->filesystem]);
}
示例3: testDeleteDirectory
/**
* cover \Magento\Theme\Model\Wysiwyg\Storage::deleteDirectory
*/
public function testDeleteDirectory()
{
$directoryPath = $this->_storageRoot . '/../root';
$this->_helperStorage->expects($this->atLeastOnce())->method('getStorageRoot')->will($this->returnValue($this->_storageRoot));
$this->directoryWrite->expects($this->once())->method('delete')->with($directoryPath);
$this->_storageModel->deleteDirectory($directoryPath);
}
示例4: testRewind
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage wrongColumnsNumber
*/
public function testRewind()
{
$this->_directoryMock->expects($this->any())->method('openFile')->will($this->returnValue(new \Magento\Framework\Filesystem\File\Read(__DIR__ . '/_files/test.csv', new \Magento\Framework\Filesystem\Driver\File())));
$model = new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/_files/test.csv', $this->_directoryMock);
$this->assertSame(-1, $model->key());
$model->next();
$this->assertSame(0, $model->key());
$model->next();
$this->assertSame(1, $model->key());
$model->rewind();
$this->assertSame(0, $model->key());
$model->next();
$model->next();
$this->assertSame(2, $model->key());
$model->current();
}
示例5: testGetDirsCollectionCreateSubDirectories
public function testGetDirsCollectionCreateSubDirectories()
{
$directoryName = 'test1';
$this->coreFileStorageMock->expects($this->once())->method('checkDbUsage')->willReturn(true);
$this->directoryCollectionMock->expects($this->once())->method('getSubdirectories')->with(self::STORAGE_ROOT_DIR)->willReturn([['name' => $directoryName]]);
$this->directoryDatabaseFactoryMock->expects($this->once())->method('create')->willReturn($this->directoryCollectionMock);
$this->directoryMock->expects($this->once())->method('create')->with(rtrim(self::STORAGE_ROOT_DIR, '/') . '/' . $directoryName);
$this->generalTestGetDirsCollection(self::STORAGE_ROOT_DIR);
}
示例6: testRunReadinessCheckLastTimestamp
public function testRunReadinessCheckLastTimestamp()
{
$this->dbValidator->expects($this->once())->method('checkDatabaseConnection')->willReturn(true);
$this->write->expects($this->once())->method('isExist')->willReturn(true);
$this->write->expects($this->once())->method('readFile')->willReturn('{"current_timestamp": 50}');
$expected = [ReadinessCheck::KEY_READINESS_CHECKS => [ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED => true], ReadinessCheck::KEY_PHP_CHECKS => $this->expected, ReadinessCheck::KEY_LAST_TIMESTAMP => 50, ReadinessCheck::KEY_CURRENT_TIMESTAMP => 100];
$expectedJson = json_encode($expected, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$this->write->expects($this->once())->method('writeFile')->with(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE, $expectedJson);
$this->readinessCheck->runReadinessCheck();
}
示例7: setUpDirectoryWriteInstallation
public function setUpDirectoryWriteInstallation()
{
// CONFIG
$this->directoryWriteMock
->expects($this->at(0))
->method('isExist')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(1))
->method('isDirectory')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(2))
->method('isReadable')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(3))
->method('isWritable')
->will($this->returnValue(true));
// VAR
$this->directoryWriteMock
->expects($this->at(4))
->method('isExist')
->will($this->returnValue(false));
// MEDIA
$this->directoryWriteMock
->expects($this->at(5))
->method('isExist')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(6))
->method('isDirectory')
->will($this->returnValue(false));
// STATIC_VIEW
$this->directoryWriteMock
->expects($this->at(7))
->method('isExist')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(8))
->method('isDirectory')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(9))
->method('isReadable')
->will($this->returnValue(true));
$this->directoryWriteMock
->expects($this->at(10))
->method('isWritable')
->will($this->returnValue(false));
}
示例8: testGetCurrentUrl
public function testGetCurrentUrl()
{
$storeId = 1;
$baseUrl = 'http://localhost';
$relativePath = '/../wysiwyg';
$this->imagesHelper->setStoreId($storeId);
$this->storeMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)->willReturn($baseUrl);
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
$this->directoryWriteMock->expects($this->any())->method('getRelativePath')->willReturn($relativePath);
$this->assertEquals($baseUrl . $relativePath . '/', $this->imagesHelper->getCurrentUrl());
}
示例9: testUploadPreviewImage
/**
* @covers \Magento\Framework\View\Design\Theme\Image::uploadPreviewImage
*/
public function testUploadPreviewImage()
{
$scope = 'test_scope';
$tmpFilePath = '/media_path/tmp/temporary.png';
$this->_themeMock->setData($this->_getThemeSampleData());
$this->_themeMock->setData('preview_image', 'test.png');
$this->_uploaderMock->expects($this->once())->method('uploadPreviewImage')->with($scope, '/media_path/tmp')->will($this->returnValue($tmpFilePath));
$this->_mediaDirectoryMock->expects($this->at(0))->method('getRelativePath')->will($this->returnArgument(0));
$this->_mediaDirectoryMock->expects($this->at(1))->method('delete')->with($this->stringContains('test.png'));
$this->_mediaDirectoryMock->expects($this->at(2))->method('delete')->with($tmpFilePath);
$this->_model->uploadPreviewImage($scope);
}
示例10: setUp
/**
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
{
$this->_filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
$this->_driverMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\DriverInterface', [], '', false, false, true, ['getRealPath']);
$this->_driverMock->expects($this->any())->method('getRealPath')->will($this->returnArgument(0));
$this->_directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['delete', 'getDriver'], [], '', false);
$this->_directoryMock->expects($this->any())->method('getDriver')->will($this->returnValue($this->_driverMock));
$this->_filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false);
$this->_filesystemMock->expects($this->any())->method('getDirectoryWrite')->with(DirectoryList::MEDIA)->will($this->returnValue($this->_directoryMock));
$this->_adapterFactoryMock = $this->getMock('Magento\\Framework\\Image\\AdapterFactory', [], [], '', false);
$this->_imageHelperMock = $this->getMock('Magento\\Cms\\Helper\\Wysiwyg\\Images', ['getStorageRoot'], [], '', false);
$this->_imageHelperMock->expects($this->any())->method('getStorageRoot')->will($this->returnValue(self::STORAGE_ROOT_DIR));
$this->_resizeParameters = ['width' => 100, 'height' => 50];
$this->_storageCollectionFactoryMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage\\CollectionFactory', [], [], '', false);
$this->_storageFileFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\FileFactory', [], [], '', false);
$this->_storageDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\DatabaseFactory', [], [], '', false);
$this->_directoryDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\Directory\\DatabaseFactory', [], [], '', false);
$this->_uploaderFactoryMock = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\UploaderFactory')->disableOriginalConstructor()->getMock();
$this->_sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false);
$this->_backendUrlMock = $this->getMock('Magento\\Backend\\Model\\Url', [], [], '', false);
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_model = $objectManagerHelper->getObject('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage', ['session' => $this->_sessionMock, 'backendUrl' => $this->_backendUrlMock, 'cmsWysiwygImages' => $this->_imageHelperMock, 'coreFileStorageDb' => $this->getMock('Magento\\MediaStorage\\Helper\\File\\Storage\\Database', [], [], '', false), 'filesystem' => $this->_filesystemMock, 'imageFactory' => $this->_adapterFactoryMock, 'assetRepo' => $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false), 'storageCollectionFactory' => $this->_storageCollectionFactoryMock, 'storageFileFactory' => $this->_storageFileFactoryMock, 'storageDatabaseFactory' => $this->_storageDatabaseFactoryMock, 'directoryDatabaseFactory' => $this->_directoryDatabaseFactoryMock, 'uploaderFactory' => $this->_uploaderFactoryMock, 'resizeParameters' => $this->_resizeParameters]);
}
示例11: testGetThumbnailPathNotFound
/**
* @test
* @return void
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The image not found
*/
public function testGetThumbnailPathNotFound()
{
$image = 'notFoundImage.png';
$root = '/image';
$sourceNode = '/not/a/root';
$node = base64_encode($sourceNode);
$this->request->expects($this->at(0))->method('getParam')->willReturnMap([[\Magento\Theme\Helper\Storage::PARAM_THEME_ID, null, 6], [\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE, null, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE], [\Magento\Theme\Helper\Storage::PARAM_NODE, null, $node]]);
$this->urlDecoder->expects($this->once())->method('decode')->with($node)->willReturnCallback(function ($path) {
return base64_decode($path);
});
$this->directoryWrite->expects($this->once())->method('isDirectory')->with($root . $sourceNode)->willReturn(true);
$this->directoryWrite->expects($this->once())->method('getRelativePath')->with($root . $sourceNode)->willReturn($sourceNode);
$this->directoryWrite->expects($this->once())->method('isExist')->with($sourceNode . '/' . $image);
$this->helper->getThumbnailPath($image);
}
示例12: _prepareSitemapModelMock
/**
* Prepare mock of Sitemap model
*
* @param array $actualData
* @param int $maxLines
* @param int $maxFileSize
* @param array $expectedFile
* @param int $expectedWrites
* @param array $robotsInfo
* @return \Magento\Sitemap\Model\Sitemap|PHPUnit_Framework_MockObject_MockObject
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareSitemapModelMock(&$actualData, $maxLines, $maxFileSize, $expectedFile, $expectedWrites, $robotsInfo)
{
// Check that all $expectedWrites lines were written
$actualData = [];
$currentFile = '';
$streamWriteCallback = function ($str) use(&$actualData, &$currentFile) {
if (!array_key_exists($currentFile, $actualData)) {
$actualData[$currentFile] = '';
}
$actualData[$currentFile] .= $str;
};
// Check that all expected lines were written
$this->_fileMock->expects($this->exactly($expectedWrites))->method('write')->will($this->returnCallback($streamWriteCallback));
// Check that all expected file descriptors were created
$this->_directoryMock->expects($this->exactly(count($expectedFile)))->method('openFile')->will($this->returnCallback(function ($file) use(&$currentFile) {
$currentFile = $file;
}));
// Check that all file descriptors were closed
$this->_fileMock->expects($this->exactly(count($expectedFile)))->method('close');
if (count($expectedFile) == 1) {
$this->_directoryMock->expects($this->once())->method('renameFile')->will($this->returnCallback(function ($from, $to) {
\PHPUnit_Framework_Assert::assertEquals('/sitemap-1-1.xml', $from);
\PHPUnit_Framework_Assert::assertEquals('/sitemap.xml', $to);
}));
}
// Check robots txt
$robotsStart = '';
if (isset($robotsInfo['robotsStart'])) {
$robotsStart = $robotsInfo['robotsStart'];
}
$robotsFinish = 'Sitemap: http://store.com/sitemap.xml';
if (isset($robotsInfo['robotsFinish'])) {
$robotsFinish = $robotsInfo['robotsFinish'];
}
$this->_directoryMock->expects($this->any())->method('readFile')->will($this->returnValue($robotsStart));
$this->_directoryMock->expects($this->any())->method('write')->with($this->equalTo('robots.txt'), $this->equalTo($robotsFinish));
// Mock helper methods
$pushToRobots = 0;
if (isset($robotsInfo['pushToRobots'])) {
$pushToRobots = (int) $robotsInfo['pushToRobots'];
}
$this->_helperMockSitemap->expects($this->any())->method('getMaximumLinesNumber')->will($this->returnValue($maxLines));
$this->_helperMockSitemap->expects($this->any())->method('getMaximumFileSize')->will($this->returnValue($maxFileSize));
$this->_helperMockSitemap->expects($this->any())->method('getEnableSubmissionRobots')->will($this->returnValue($pushToRobots));
$model = $this->_getModelMock(true);
return $model;
}
示例13: testClearNotExist
public function testClearNotExist()
{
$this->directoryWriteMock->expects($this->never())->method('delete');
$this->webLogger->clear();
}
示例14: testConstructorFileDestinationMatch
/**
* Test destination argument for the second getRelativePath after preg_replace.
*
* @depends testConstructorInternalCalls
* @dataProvider constructorFileDestinationMatchDataProvider
*/
public function testConstructorFileDestinationMatch($fileName, $expectedfileName)
{
$this->directory->expects($this->at(0))->method('getRelativePath')->with($fileName);
$this->directory->expects($this->at(1))->method('getRelativePath')->with($expectedfileName);
$this->_invokeConstructor($fileName);
}