PrefixFilesystem example

/** * @internal */
class PrefixFilesystemTest extends TestCase
{
    public function testPrefix(): void
    {
        $generator = $this->createMock(TemporaryUrlGenerator::class);
        $generator->method('temporaryUrl')->willReturn('http://example.com/temporary-url');

        $fs = new Filesystem(new MemoryFilesystemAdapter()['public_url' => 'http://example.com'], null, null, $generator);
        $prefix = new PrefixFilesystem($fs, 'foo');

        $prefix->write('foo.txt', 'bla');
        static::assertTrue($prefix->fileExists('foo.txt'));
        static::assertTrue($prefix->has('foo.txt'));
        static::assertFalse($prefix->directoryExists('foo.txt'));
        static::assertTrue($fs->has('foo/foo.txt'));
        static::assertFalse($fs->directoryExists('foo/foo.txt'));

        static::assertSame('bla', $prefix->read('foo.txt'));
        static::assertSame('bla', stream_get_contents($prefix->readStream('foo.txt')));
        static::assertSame('text/plain', $prefix->mimeType('foo.txt'));
        
Home | Imprint | This part of the site doesn't use cookies.