Модульное тестирование Spat ie laravel - загрузка файла медиабиблиотеки - PullRequest
0 голосов
/ 25 мая 2020

У меня возникают проблемы с запуском модульного теста для загрузки файла и сохранением файла с помощью Spat ie medialibrary .

Код отлично работает в браузере: файл сохраняется правильно.

Однако этот модульный тест не проходит:

        Storage::fake('resource-files');
        $file = UploadedFile::fake()->create('courtform.pdf', 1024);

        $response = $this->ActingAs($this->adminUser())
                        ->json('PATCH', '/forms/' . $dbentry->id, [
            'name' => 'Form 800',
            'state' => 'VT',
            'description' => 'General info form',
            'file' => $file,
        ]);

        // Assert the file was stored...
        Storage::disk('resource-files')->assertExists('1/courtform.pdf');

Он не выполняется, потому что тип mime пуст:

Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileUnacceptableForCollection^ {#1485
  #message: "The file with properties `name: courtform.pdf, size: 0, mime: inode/x-empty` was not accepted into the collection named `source-pdfs` of model `App\Form` with id `1`"

... и я потребовали, чтобы файлы в этой коллекции были PDF-файлами:

    public function registerMediaCollections()
    {
      // Keep only one file per model
      $this
            ->addMediaCollection('source-pdfs')
            ->useDisk('resource-files')
            ->singleFile()
            ->acceptsFile(function (File $file) {
            return $file->mimeType === 'application/pdf';
          });

      $this
            ->addMediaCollection('source-fdfs')
            ->singleFile();

    }

Но этот пустой mimeType - проблема только в модульном тесте - это не проблема в браузере.

Кто-нибудь знает почему свойства файла могут быть size: 0, mime: inode/x-empty при оценке с помощью registerMediaCollections ()?

Спасибо!

...