Answer the question
In order to leave comments, you need to log in
Laravel. PHPUnit. Why doesn't downloading test files work?
The test itself:
<?php
class RegistrationTest extends TestCase
{
public function testRegisterClient()
{
$file = base_path('tests/assets/img/photo.jpeg');
$photo = new \Symfony\Component\HttpFoundation\File\UploadedFile($file, 'photo.jpeg',
mime_content_type($file), filesize($file), null, true);
$response = $this->action('POST', '[email protected]', [], [
'number' => $data['number'],
'token' => $data['token'],
'type' => 'client',
'name' => 'Сергей Семенко',
'city' => 'Харьков',
], [], ['photo' => $photo]);
$response = json_decode($response->getContent());
}
}
private function registerUser(Request $request, PreRegister $preRegister) : User
{
$validator = \Validator::make($request->all(), [
'name' => 'required|string|max:255',
'photo' => 'required|mimes:jpeg,jpg,bmp,png,gif',
'city' => 'required|string|max:255',
], [
'name.required' => 'Не указано имя/название',
'name.string' => 'Ошибка чтения имени/названия',
'name.max' => 'Имя должно содержать не более :max символов',
'photo.required' => 'Не выбрано фото',
'photo.mimes' => 'Ошибка открытия фото',
'photo.max' => 'Максимальный размер фото 10МБ',
'city.required' => 'Не указан город',
'city.string' => 'Ошибка чтения города',
'city.max' => 'Название города может содержать не более :max символов',
]);
$file = $request->file('photo');
dd($file); // Результат вывода ниже
if (!$validator->fails()) {
$photo = Photo::fromUploadedFile($request->file('image'));
$user = new User();
$user->name = $request->get('name');
$user->photo()->associate($photo);
$user->number = $preRegister->number;
return $user;
}
throw new ValidationException($validator);
}
Illuminate\Http\UploadedFile {#324
-test: false
-originalName: "photo.jpeg"
-mimeType: "image/jpeg"
-size: 8388
-error: 0
path: "C:\OpenServer\domains\test\tests/assets/img"
filename: "photo.jpeg"
basename: "photo.jpeg"
pathname: "C:\OpenServer\domains\test\tests/assets/img/photo.jpeg"
extension: "jpeg"
realPath: "C:\OpenServer\domains\test\tests\assets\img\photo.jpeg"
aTime: 2016-06-27 16:11:13
mTime: 2016-03-20 13:56:50
cTime: 2016-06-27 16:11:13
inode: 0
size: 8388
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\OpenServer\domains\test\tests\assets\img\photo.jpeg"
}
Answer the question
In order to leave comments, you need to log in
Use \Illuminate\Http\UploadedFile
instead
\Symfony\Component\HttpFoundation\File\UploadedFile
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question