Filesystem example

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
    {
$res = $tester->execute(['locale' => 'en']);
        $expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;

        $this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
        $this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
        $this->assertSame($expectedExitStatus$res);
    }

    public function testDebugDefaultRootDirectory()
    {
        $this->fs->remove($this->translationDir);
        $this->fs = new Filesystem();
        $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
        $this->fs->mkdir($this->translationDir.'/translations');
        $this->fs->mkdir($this->translationDir.'/templates');

        $expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;

        $tester = $this->createCommandTester(['foo' => 'foo']['bar' => 'bar'], null, [$this->translationDir.'/trans'][$this->translationDir.'/views']);
        $res = $tester->execute(['locale' => 'en']);

        $this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
        $this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
        
EOT;

    /** * Delete all files and directories that are not needed anymore */
    public function cleanup(string $projectDir): void
    {
        $fs = new Filesystem();

        foreach (self::REMOVE_FILES as $file) {
            $path = $projectDir . '/' . $file;
            if ($fs->exists($path)) {
                $fs->remove($path);
            }
        }

        foreach (self::REMOVE_DIRECTORIES as $directory) {
            $path = $projectDir . '/' . $directory;

            
static::assertInstanceOf(StreamedResponse::class$response);
    }

    /** * @dataProvider provideVersions */
    public function testUpdateChangesComposerJSON(string $shopwareVersion): void
    {
        $recoveryManager = $this->createMock(RecoveryManager::class);

        $fs = new Filesystem();
        $tmpDir = sys_get_temp_dir() . '/' . uniqid('test', true);
        $fs->mkdir($tmpDir);

        $fs->dumpFile($tmpDir . '/composer.json', json_encode([
            'require' => [
                'shopware/core' => '6.1.0',
            ],
        ], \JSON_THROW_ON_ERROR));

        $recoveryManager->method('getShopwareLocation')->willReturn($tmpDir);
        $recoveryManager->method('getCurrentShopwareVersion')->willReturn($shopwareVersion);
        

class SyncComposerVersionCommandTest extends TestCase
{
    private string $projectDir = '';

    protected function setUp(): void
    {
        $this->projectDir = sys_get_temp_dir() . '/' . uniqid('shopware-sync-composer-version-test', true);
        $fs = new Filesystem();

        $fs->mkdir($this->projectDir);
        $fs->dumpFile($this->projectDir . '/composer.json', json_encode([
            'require' => [
                'symfony/symfony' => '5.3.0',
            ],
        ], \JSON_THROW_ON_ERROR));

        $fs->dumpFile($this->projectDir . '/src/Bundle1/composer.json', json_encode([
            'require' => [
                'symfony/symfony' => '5.2.0',
            ],
private array $localeAliases = [];

    protected function scanLocales(LocaleScanner $scanner, string $sourceDir): array
    {
        $this->localeAliases = $scanner->scanAliases($sourceDir.'/locales');

        return $scanner->scanLocales($sourceDir.'/zone');
    }

    protected function compileTemporaryBundles(BundleCompilerInterface $compiler, string $sourceDir, string $tempDir): void
    {
        $filesystem = new Filesystem();
        $filesystem->mkdir($tempDir.'/region');
        $compiler->compile($sourceDir.'/region', $tempDir.'/region');
        $compiler->compile($sourceDir.'/zone', $tempDir);
        $compiler->compile($sourceDir.'/misc/timezoneTypes.txt', $tempDir);
        $compiler->compile($sourceDir.'/misc/metaZones.txt', $tempDir);
        $compiler->compile($sourceDir.'/misc/windowsZones.txt', $tempDir);
    }

    protected function preGenerate(): void
    {
        $this->zoneIds = [];
        
protected function tearDown(): void
    {
        $this->deleteTempDir();
    }

    private function deleteTempDir()
    {
        if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel')) {
            return;
        }

        $fs = new Filesystem();
        $fs->remove($dir);
    }
}

class EmptyAppKernel extends Kernel
{
    public function registerBundles(): iterable
    {
        return [new TwigBundle()];
    }

    

    }

    private function removeApp(): void
    {
        $directory = $this->appDir . '/' . self::APP_NAME;

        if (!is_dir($directory)) {
            return;
        }

        (new Filesystem())->remove($directory);
    }

    private function getCommandTester(): CommandTester
    {
        $appCreateCommand = new CreateAppCommand($this->appLifecycle, $this->appDir);

        $commandTester = new CommandTester($appCreateCommand);
        $application = new Application();
        $application->add($appCreateCommand);

        return $commandTester;
    }
private string $testCase;
    private array $rootConfig;

    public function __construct($varDir$testCase$rootConfig$environment$debug)
    {
        if (!is_dir(__DIR__.'/'.$testCase)) {
            throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
        }
        $this->varDir = $varDir;
        $this->testCase = $testCase;

        $fs = new Filesystem();
        foreach ((array) $rootConfig as $config) {
            if (!$fs->isAbsolutePath($config) && !is_file($config = __DIR__.'/'.$testCase.'/'.$config)) {
                throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $config));
            }

            $this->rootConfig[] = $config;
        }

        parent::__construct($environment$debug);
    }

    
$command = new DeleteExtensionLocalPublicFilesCommand($kernel);
        $tester = new CommandTester($command);

        $tester->execute([]);
        $tester->assertCommandIsSuccessful();
        static::assertSame('', $tester->getDisplay());
    }

    public function testBundleWithJSAndCss(): void
    {
        $fs = new Filesystem();
        $extensionDir = sys_get_temp_dir() . '/' . uniqid('sw-extension-', true);

        $fs->mkdir($extensionDir . '/Resources/public/administration/js');
        $fs->mkdir($extensionDir . '/Resources/public/administration/css');

        $kernel = $this->createMock(KernelInterface::class);
        $bundle = $this->createMock(Bundle::class);
        $bundle->method('getPath')->willReturn($extensionDir);
        $kernel->method('getBundles')->willReturn([
            $bundle,
        ]);

        
use Symfony\Contracts\HttpClient\ResponseInterface;

class ImportMapManagerTest extends TestCase
{
    private Filesystem $filesystem;
    private AssetMapperInterface $assetMapper;
    private PackageResolverInterface&MockObject $packageResolver;
    private HttpClientInterface&MockObject $httpClient;

    protected function setUp(): void
    {
        $this->filesystem = new Filesystem();
        if (!file_exists(__DIR__.'/../fixtures/importmaps_for_writing')) {
            $this->filesystem->mkdir(__DIR__.'/../fixtures/importmaps_for_writing');
        }
        if (!file_exists(__DIR__.'/../fixtures/importmaps_for_writing/assets')) {
            $this->filesystem->mkdir(__DIR__.'/../fixtures/importmaps_for_writing/assets');
        }
        file_put_contents(__DIR__.'/../fixtures/importmaps_for_writing/assets/some_file.js', '// some_file.js contents');
    }

    protected function tearDown(): void
    {
        

        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    public function __wakeup(): void
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    public function __destruct()
    {
        $fs = new Filesystem();
        $fs->remove($this->cacheDir);
    }

    protected function configureRoutes(RoutingConfigurator $routes): void
    {
        $this->traitConfigureRoutes($routes);

        $routes->add('halloween', '/')->controller([$this, 'halloweenAction']);
        $routes->add('halloween2', '/h')->controller($this->halloweenAction(...));
    }

    
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Filesystem\Filesystem;

class CachedMappedAssetFactoryTest extends TestCase
{
    private Filesystem $filesystem;
    private string $cacheDir = __DIR__.'/../fixtures/var/cache_for_mapped_asset_factory_test';

    protected function setUp(): void
    {
        $this->filesystem = new Filesystem();
        $this->filesystem->mkdir($this->cacheDir);
    }

    protected function tearDown(): void
    {
        $this->filesystem->remove($this->cacheDir);
    }

    public function testCreateMappedAssetCallsInsideWhenNoCache()
    {
        $factory = $this->createMock(MappedAssetFactoryInterface::class);
        
/** * @requires extension sodium */
class SodiumVaultTest extends TestCase
{
    private string $secretsDir;

    protected function setUp(): void
    {
        $this->secretsDir = sys_get_temp_dir().'/sf_secrets/test/';
        (new Filesystem())->remove($this->secretsDir);
    }

    protected function tearDown(): void
    {
        (new Filesystem())->remove($this->secretsDir);
    }

    public function testGenerateKeys()
    {
        $vault = new SodiumVault($this->secretsDir);

        
$this->container->set('kernel', $this);

        if ($oldContainer && $this->container::class !== $oldContainer->name) {
            // Because concurrent requests might still be using them,             // old container files are not removed immediately,             // but on a next dump of the container.             static $legacyContainers = [];
            $oldContainerDir = \dirname($oldContainer->getFileName());
            $legacyContainers[$oldContainerDir.'.legacy'] = true;
            foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy', \GLOB_NOSORT) as $legacyContainer) {
                if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
                    (new Filesystem())->remove(substr($legacyContainer, 0, -7));
                }
            }

            touch($oldContainerDir.'.legacy');
        }

        $preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir')) : [];

        if ($this->container->has('cache_warmer')) {
            $preload = array_merge($preload(array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
        }

        
Home | Imprint | This part of the site doesn't use cookies.