serviceLocator = ServiceManager::getServiceManager(); $this->filesystem = $this->serviceLocator->get(FileSystemService::SERVICE_ID)->getFileSystem('taoQtiTestSessionFilesystem'); $this->fileManager = new QtiFlysystemFileManager(); $this->fileManager->setFilePrefix('unittest'); $this->fileManager->setServiceLocator($this->serviceLocator); $this->cleanUp(); } public function tearDown(): void { $this->cleanUp(); } public function cleanUp() { foreach ($this->filesystem->listContents('/', true) as $file) { $basename = $file['basename']; if (strpos($basename, 'unittest') !== false) { $this->filesystem->delete($file['path']); } } } public function testCreateFromDataWithFilename() { $file = $this->fileManager->createFromData('pouet', 'text/plain', 'myfile.txt'); $this->assertInstanceOf(QtiFlysystemFile::class, $file); $this->assertEquals('pouet', $file->getData()); $this->assertEquals('text/plain', $file->getMimeType()); $this->assertTrue($file->hasFilename()); $this->assertEquals('myfile.txt', $file->getFilename()); $this->assertInternalType('resource', $file->getStream()); } /** * @depends testCreateFromDataWithFilename */ public function testRetrieve() { $file = $this->fileManager->createFromData('pouet', 'text/plain', 'myfile.txt'); $file2 = $this->fileManager->retrieve($file->getIdentifier()); $this->assertEquals($file->getIdentifier(), $file2->getIdentifier()); $this->assertEquals($file->getMimeType(), $file->getMimeType()); $this->assertEquals($file->getFilename(), $file->getFilename()); } /** * @depends testCreateFromDataWithFilename */ public function testDelete() { $file = $this->fileManager->createFromData('check', 'text/plain', 'myfile.txt'); $this->assertTrue($this->filesystem->has($file->getIdentifier())); $this->fileManager->delete($file); $this->assertFalse($this->filesystem->has($file->getIdentifier())); } }