linkInterfaceFactoryMock = $this->getMockBuilder(LinkInterfaceFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $this->fileInfoManagerMock = $this->getMockBuilder(FileInfoManager::class) ->disableOriginalConstructor() ->getMock(); $this->storeManagerInterfaceMock = $this->getMockBuilder(StoreManagerInterface::class) ->getMockForAbstractClass(); $this->linkInterfaceMock = $this->getMockBuilder(LinkInterface::class) ->getMockForAbstractClass(); $this->fileInfoMock = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->getMock(); $this->storeMock = $this->getMockBuilder(Store::class) ->disableOriginalConstructor() ->getMock(); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->linkProvider = $this->objectManagerHelper->getObject( LinkProvider::class, [ 'linkFactory' => $this->linkInterfaceFactoryMock, 'fileInfoManager' => $this->fileInfoManagerMock, 'storeManager' => $this->storeManagerInterfaceMock ] ); } public function testGet() { $baseUrl = 'http://magento.local/pub/media/'; $fileInfoPath = 'analytics/data.tgz'; $fileInitializationVector = 'er312esq23eqq'; $this->fileInfoManagerMock->expects($this->once()) ->method('load') ->willReturn($this->fileInfoMock); $this->linkInterfaceFactoryMock->expects($this->once()) ->method('create') ->with( [ 'initializationVector' => base64_encode($fileInitializationVector), 'url' => $baseUrl . $fileInfoPath ] ) ->willReturn($this->linkInterfaceMock); $this->storeManagerInterfaceMock->expects($this->once()) ->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once()) ->method('getBaseUrl') ->with( UrlInterface::URL_TYPE_MEDIA ) ->willReturn($baseUrl); $this->fileInfoMock->expects($this->atLeastOnce()) ->method('getPath') ->willReturn($fileInfoPath); $this->fileInfoMock->expects($this->atLeastOnce()) ->method('getInitializationVector') ->willReturn($fileInitializationVector); $this->assertEquals($this->linkInterfaceMock, $this->linkProvider->get()); } /** * @param string|null $fileInfoPath * @param string|null $fileInitializationVector * * @dataProvider fileNotReadyDataProvider * @expectedException \Magento\Framework\Exception\NoSuchEntityException * @expectedExceptionMessage File is not ready yet. */ public function testFileNotReady($fileInfoPath, $fileInitializationVector) { $this->fileInfoManagerMock->expects($this->once()) ->method('load') ->willReturn($this->fileInfoMock); $this->fileInfoMock->expects($this->once()) ->method('getPath') ->willReturn($fileInfoPath); $this->fileInfoMock->expects($this->any()) ->method('getInitializationVector') ->willReturn($fileInitializationVector); $this->linkProvider->get(); } /** * @return array */ public function fileNotReadyDataProvider() { return [ [null, 'initVector'], ['path', null], ['', 'initVector'], ['path', ''], ['', ''], [null, null] ]; } }