public function testToArray() { $contents = ['content1', 'content2']; $expectedArray = []; $index = 0; foreach ($this->filePaths as $filePath) { $expectedArray[$filePath] = $contents[$index]; $this->fileReadFactory->expects($this->at($index))->method('create')->with($filePath)->willReturn($this->fileRead); $this->fileRead->expects($this->at($index))->method('readAll')->will($this->returnValue($contents[$index++])); } $this->assertEquals($expectedArray, $this->fileIterator->toArray()); }
/** * @dataProvider moveFileUrlDataProvider */ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName) { $expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName; $this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath); // Check writeFile() method invoking. $this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue(null)); // Create adjusted reader which does not validate path. $readMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\File\\Read')->disableOriginalConstructor()->setMethods(['readAll'])->getMock(); // Check readAll() method invoking. $readMock->expects($this->once())->method('readAll')->will($this->returnValue(null)); $this->readFactory = $this->getMockBuilder('\\Magento\\Framework\\Filesystem\\File\\ReadFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); // Check create() method invoking with expected argument. $this->readFactory->expects($this->once())->method('create')->will($this->returnValue($readMock))->with($expectedHost); $uploaderMock = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Uploader')->setConstructorArgs([$this->coreFileStorageDb, $this->coreFileStorage, $this->imageFactory, $this->validator, $this->filesystem, $this->readFactory])->setMethods(['_setUploadFile', 'save', 'getTmpDir'])->getMock(); //Check invoking of getTmpDir(), _setUploadFile(), save() methods. $uploaderMock->expects($this->any())->method('getTmpDir')->will($this->returnValue('')); $uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); $uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null])); $uploaderMock->move($fileUrl); }
protected function _setupUrlMocks($size = self::FILE_SIZE, $url = self::URL, $additionalStatData = []) { $this->_handleMock->expects($this->any())->method('stat')->will($this->returnValue(array_merge(['size' => $size, 'type' => self::MIME_TYPE], $additionalStatData))); $this->fileReadFactory->expects($this->once())->method('create')->will($this->returnValue($this->_handleMock)); $this->_helper->setResource($url, DownloadHelper::LINK_TYPE_URL); }
public function testGetRemoteResource() { $fileReadMock = $this->getMock('Magento\\Framework\\Filesystem\\File\\ReadInterface', array(), array(), '', false); $this->_fileReadFactoryMock->expects($this->once())->method('create')->with('example.com', 'http')->will($this->returnValue($fileReadMock)); $this->assertEquals($fileReadMock, $this->_filesystem->getRemoteResource('http://example.com')); }