ImportExportFileEntity example

static::assertEquals(Response::HTTP_OK, $response->getStatusCode());
        static::assertIsString($header = $response->headers->get('Content-Disposition'));
        static::assertStringContainsString($expectOutputFilename$header);
    }

    /** * @return iterable<string, array{fileEntity: ImportExportFileEntity, accessToken: string}> */
    public static function dataProviderInvalidAccessToken(): iterable
    {
        yield 'empty access token' => [
            'fileEntity' => (new ImportExportFileEntity())->assign([
                'id' => Uuid::randomHex(),
                'accessToken' => '',
            ]),
            'accessToken' => 'validAccessToken',
        ];

        yield 'mismatched access token' => [
            'fileEntity' => (new ImportExportFileEntity())->assign([
                'id' => Uuid::randomHex(),
                'accessToken' => 'validAccessToken',
            ]),
            
$writer = $this->createMock(AbstractWriter::class);
        $writer->expects(static::never())->method('append');

        $pipe = $this->createMock(AbstractPipe::class);
        $pipe->expects(static::never())->method('in');
        $pipe->expects(static::never())->method('out');

        $logEntity = new ImportExportLogEntity();
        $logEntity->assign([
            'id' => Uuid::randomHex(),
            'file' => (new ImportExportFileEntity())->assign([
                'path' => 'foobar', 'size' => 1337,
            ]),
            'records' => 5,
        ]);

        $importExportService = $this->createMock(ImportExportService::class);
        $importExport = new ImportExport(
            $importExportService,
            $logEntity,
            $this->getContainer()->get('shopware.filesystem.private'),
            $this->createMock(EventDispatcherInterface::class),
            
$writer = $this->createMock(AbstractWriter::class);
        $writer->expects(static::never())->method('append');

        $pipe = $this->createMock(AbstractPipe::class);
        $pipe->expects(static::never())->method('in');
        $pipe->expects(static::never())->method('out');

        $logEntity = new ImportExportLogEntity();
        $logEntity->assign([
            'id' => Uuid::randomHex(),
            'file' => (new ImportExportFileEntity())->assign([
                'path' => 'foobar', 'size' => 1337,
            ]),
            'records' => 5,
        ]);

        $importExportService = $this->createMock(ImportExportService::class);
        $importExport = new ImportExport(
            $importExportService,
            $logEntity,
            $this->createMock(FilesystemOperator::class),
            $this->createMock(EventDispatcherInterface::class),
            
$fileData = [
            'id' => $id,
            'originalName' => $originalFileName,
            'path' => $path,
            'size' => $this->filesystem->fileSize($path),
            'expireDate' => $expireDate,
            'accessToken' => null,
        ];

        $this->fileRepository->create([$fileData]$context);

        $fileEntity = new ImportExportFileEntity();
        $fileEntity->assign($fileData);

        return $fileEntity;
    }

    public function detectType(UploadedFile $file): string
    {
        // TODO: we should do a mime type detection on the file content         $guessedExtension = $file->guessClientExtension();
        if ($guessedExtension === 'csv' || $file->getClientOriginalExtension() === 'csv') {
            return 'text/csv';
        }
Home | Imprint | This part of the site doesn't use cookies.