Я использую тестовый метод для проверки работы загрузки. Пока все хорошо.
Часть контроллера, до которой невозможно добраться (поскольку проверка не удалась (
Код: Выделить всё
importfile needs to be a file.
Код: Выделить всё
public function importCustomers(ImportCustomersRequest $request)
{
dump('importCustomers called!');
Код: Выделить всё
public function rules(): array
{
dump('importfile', $this->importfile);
return [
'importfile' => 'required|file',
];
}
Код: Выделить всё
$file = UploadedFile::fake()->createWithContent('customer.csv', 'id;name;group\n9999;Customer1;');
// other approachs that did not work:
// $file = UploadedFile::fake()->create('customer.csv')
//
// testing with a real file would be ok too (the file exists!) - but nada (i receive the file content instead of an UploadedFile):
// $file = Storage::path('development/customers.csv')
$response = $this->post(route('import.customers', ['importfile' => $file]));
$response->assertStatus(302);
...
Код: Выделить всё
Illuminate\Http\UploadedFile {#2053 ▼
-test: false
-originalName: "customers.csv"
-mimeType: "text/csv"
-error: 0
...
Код: Выделить всё
array:2 [
"name" => "customer.csv"
"sizeToReport" => "67"
]
Как мне загрузить тестовый файл (желательно реальный файл с содержимым), который пройдет проверку (UploadedFile< /код>)?
Подробнее здесь: https://stackoverflow.com/questions/752 ... -real-file