MemoryFilesystemAdapter example


class FlysystemLastModifiedVersionStrategyTest extends TestCase
{
    private Filesystem $fs;

    private UrlPackage $asset;

    private FlysystemLastModifiedVersionStrategy $strategy;

    protected function setUp(): void
    {
        $this->fs = new Filesystem(new MemoryFilesystemAdapter());
        $this->strategy = new FlysystemLastModifiedVersionStrategy('test', $this->fs, new TagAwareAdapter(new ArrayAdapter()new ArrayAdapter()));
        $this->asset = new UrlPackage(['http://shopware.com']$this->strategy);
    }

    public function testNonExistentFile(): void
    {
        $url = $this->asset->getUrl('test');
        static::assertSame('http://shopware.com/test', $url);
    }

    public function testExistsFile(): void
    {
static::assertEquals($expected$actual);
    }

    public function testCompileWithoutAssets(): void
    {
        $resolver = $this->createMock(ThemeFileResolver::class);
        $resolver->method('resolveFiles')->willReturn([ThemeFileResolver::SCRIPT_FILES => new FileCollection(), ThemeFileResolver::STYLE_FILES => new FileCollection()]);

        $importer = $this->createMock(ThemeFileImporter::class);

        $fs = new Filesystem(new MemoryFilesystemAdapter());
        $tmpFs = new Filesystem(new MemoryFilesystemAdapter());

        $compiler = new ThemeCompiler(
            $fs,
            $tmpFs,
            $resolver,
            true,
            $this->createMock(EventDispatcher::class),
            $importer,
            [],
            $this->createMock(CacheInvalidator::class),
            
use League\Flysystem\Visibility;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\Adapter\Filesystem\MemoryFilesystemAdapter;

/** * @internal */
class InMemoryFilesystemAdapterTest extends TestCase
{
    public function testDelete(): void
    {
        $memoryFilesystemAdapter = new MemoryFilesystemAdapter();
        $fs = new Filesystem($memoryFilesystemAdapter);
        $fs->write('a.txt', 'foo');
        static::assertTrue($fs->fileExists('a.txt'));
        static::assertFalse($fs->directoryExists('a.txt'));
        $memoryFilesystemAdapter->deleteEverything();

        static::assertFalse($fs->fileExists('a.txt'));
        static::assertFalse($fs->directoryExists('a.txt'));

        $fs->write('a.txt', 'foo');
        static::assertTrue($fs->fileExists('a.txt'));
        
if (!file_exists($testFolder)) {
            mkdir($testFolder);
        }

        $resolver = $this->createMock(ThemeFileResolver::class);
        $resolver->method('resolveFiles')->willReturn([ThemeFileResolver::SCRIPT_FILES => new FileCollection(), ThemeFileResolver::STYLE_FILES => new FileCollection()]);

        $importer = $this->createMock(ThemeFileImporter::class);
        $importer->method('getCopyBatchInputsForAssets')->with($testFolder);

        $fs = new Filesystem(new MemoryFilesystemAdapter());
        $tmpFs = new Filesystem(new MemoryFilesystemAdapter());

        $compiler = new ThemeCompiler(
            $fs,
            $tmpFs,
            $resolver,
            true,
            $this->getContainer()->get('event_dispatcher'),
            $importer,
            [],
            $this->createMock(CacheInvalidator::class),
            
/** * @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')));
        

class AssetServiceTest extends TestCase
{
    public function testCopyAssetsFromBundlePluginDoesNotExists(): void
    {
        $kernelMock = $this->createMock(KernelInterface::class);
        $kernelMock->expects(static::once())
            ->method('getBundle')
            ->with('bundleName')
            ->willThrowException(new \InvalidArgumentException());

        $filesystem = new Filesystem(new MemoryFilesystemAdapter());
        $assetService = new AssetService(
            $filesystem,
            $filesystem,
            $kernelMock,
            new StaticKernelPluginLoader($this->createMock(ClassLoader::class)),
            $this->createMock(CacheInvalidator::class),
            $this->createMock(AbstractAppLoader::class),
            new ParameterBag(['shopware.filesystem.asset.type' => 's3'])
        );

        static::expectException(PluginNotFoundException::class);
        
use Shopware\Core\Framework\Adapter\Filesystem\MemoryFilesystemAdapter;
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\CopyBatch;
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\CopyBatchInput;

/** * @internal */
class CopyBatchTest extends TestCase
{
    public function testCopy(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());

        $tmpFile = sys_get_temp_dir() . '/' . uniqid('test', true);
        file_put_contents($tmpFile, 'test');

        $sourceFile = fopen($tmpFile, 'rb');
        static::assertIsResource($sourceFile);
        CopyBatch::copy($fsnew CopyBatchInput($tmpFile['test.txt'])new CopyBatchInput($sourceFile['test2.txt']));

        static::assertTrue($fs->fileExists('test.txt'));
        static::assertTrue($fs->fileExists('test2.txt'));
        static::assertSame('test', $fs->read('test.txt'));
        

    }

    public static function resetInstances(): void
    {
        static::clearInstancesMemory();
        static::$instances = [];
    }

    public function create(array $config): FilesystemAdapter
    {
        $adapter = new MemoryFilesystemAdapter();
        static::addAdapter($adapter);

        return $adapter;
    }

    public function getType(): string
    {
        return 'memory';
    }

    private static function addAdapter(MemoryFilesystemAdapter $adapter): void
    {
private Filesystem $filesystem;

    private MockObject&EntityRepository $documentRepository;

    private MailerTransportDecorator $decorator;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(TransportInterface::class);
        $this->attachmentsBuilder = $this->createMock(MailAttachmentsBuilder::class);
        $this->filesystem = new Filesystem(new MemoryFilesystemAdapter());
        $this->documentRepository = $this->createMock(EntityRepository::class);

        $this->decorator = new MailerTransportDecorator(
            $this->decorated,
            $this->attachmentsBuilder,
            $this->filesystem,
            $this->documentRepository
        );
    }

    public function testMailerTransportDecoratorDefault(): void
    {
Home | Imprint | This part of the site doesn't use cookies.