generateFile('/testDirectory/fileRename.txt'); $directory = $this->tempDirectory->getDirectory('testDirectory'); $this->assertTrue($directory->rename('testDirectory.back')); } public function testDirectoryRenameAlreadyExistException() { $this->generateFile('/testDirectory.exist/fileRename.txt'); $directory = $this->tempDirectory->getDirectory('testDirectory.exist'); $this->expectException(\common_exception_FileSystemError::class); $directory->rename('testDirectory.exist'); } public function testGetFullPathFile() { $file = $this->getTempDirectory()->getFile('fixture'); $fileSystemId = $file->getFileSystemId(); $fileSystemService = new FileSystemService([ FileSystemService::OPTION_FILE_PATH => '/tmp/testing', FileSystemService::OPTION_ADAPTERS => [ $fileSystemId => [ 'class' => FileSystemService::FLYSYSTEM_LOCAL_ADAPTER, 'options' => ['root' => $file->getFileSystemId()] ] ], ]); $file = $this->getTempDirectory()->getFile('fixture'); $result = $fileSystemService->getFileAdapterByFile($file); $this->assertEquals($result->getPathPrefix(), 'unit-test/'); } /** * @return bool * @throws \League\Flysystem\FileExistsException * @throws \common_Exception */ private function generateFile($path) { $dir = $this->getTempDirectory(); $this->testFile = $dir->getFile($path); $this->testFile->write($path, 'PHP Unit test file'); return true; } /** * @return Directory */ private function getTempDirectory() { if (!$this->tempDirectory) { $this->tempDirectory = $this->getFileSystemMock(['unit-test'])->getDirectory('unit-test'); } return $this->tempDirectory; } /** * @return FileSystemService */ private function getMockFileSystem() { if ($this->fileSystemService === null) { $this->fileSystemService = $this->getServiceLocatorMock([FileSystemService::SERVICE_ID => new FileSystemService()])->get(FileSystemService::SERVICE_ID); } return $this->fileSystemService; } }