84 lines
2.5 KiB
PHP
84 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace IQParts\ContentTest\Unit;
|
|
|
|
use IQParts\Content\Filesystem;
|
|
use IQParts\Content\Object\File;
|
|
use IQParts\Content\Object\Folder;
|
|
use IQParts\Content\Object\Item;
|
|
use League\Flysystem\Adapter\Local;
|
|
use League\Flysystem\FileNotFoundException;
|
|
use League\Flysystem\Filesystem as FlySystem;
|
|
|
|
use IQParts\ContentTest\AbstractTestCase;
|
|
|
|
/**
|
|
* Class FilesystemTest
|
|
* @package IQParts\ContentTest\Unit
|
|
*/
|
|
final class FilesystemTest extends AbstractTestCase
|
|
{
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function testFilesystem()
|
|
{
|
|
$fs = new Filesystem(new Local(__DIR__ . '/../files'));
|
|
|
|
$this->assertTrue($fs->exists('test.txt'));
|
|
$this->assertInstanceOf(File::class, $fs->get('test.txt'));
|
|
$this->assertInstanceOf(Folder::class, $fs->get('folder'));
|
|
$fs->put('test.txt', 'test');
|
|
$this->assertEquals('test', $fs->get('test.txt')->getContents());
|
|
$fs->put('test.txt', '');
|
|
|
|
foreach ($fs->listDirs('folder') as $dir) {
|
|
$this->assertInstanceOf(Folder::class, $dir);
|
|
}
|
|
foreach ($fs->listFiles('') as $file) {
|
|
$this->assertInstanceOf(File::class, $file);
|
|
}
|
|
|
|
$resource = $fs->getStream('test.txt');
|
|
$this->assertTrue(is_resource($resource));
|
|
$this->assertTrue($fs->putStream('test.txt', $resource));
|
|
fclose($resource);
|
|
|
|
$this->assertTrue($fs->createDir('testing'));
|
|
$this->assertTrue($fs->exists('testing'));
|
|
$fs->deleteDir('testing');
|
|
$this->assertFalse($fs->exists('testing'));
|
|
|
|
$fs->put('test2.txt', '');
|
|
$this->assertTrue($fs->exists('test2.txt'));
|
|
$fs->delete('test2.txt');
|
|
$this->assertFalse($fs->exists('test2.txt'));
|
|
|
|
$this->assertInstanceOf(FlySystem::class, $fs->getFlySystem());
|
|
|
|
$folder = $fs->get('/');
|
|
$this->assertInstanceOf(Folder::class, $folder);
|
|
$this->assertEquals([
|
|
base64_encode('test.txt')
|
|
],
|
|
$folder->getFiles()
|
|
);
|
|
$this->assertEquals(base64_encode('folder'), $folder->getDirs()[0]);
|
|
|
|
foreach ($fs->listDirs('/') as $dir) {
|
|
$this->assertInstanceOf(Folder::class, $dir);
|
|
}
|
|
|
|
foreach ($fs->listFiles('/') as $file) {
|
|
$this->assertInstanceOf(File::class, $file);
|
|
}
|
|
|
|
foreach ($fs->listDirContents('folder', false) as $item) {
|
|
$this->assertInstanceOf(Item::class, $item);
|
|
}
|
|
|
|
$this->expectException(FileNotFoundException::class);
|
|
$fs->get('does-not-exist');
|
|
}
|
|
} |