0

我不知道如何使用 dataProvider 进行带有文件字段的 laravel 测试:

public function requiredFormValidationProvider()
    {
        $faker = Faker::create('es_ES');
        $password = $faker->password;
        $avatar = File::create('avatar', 200);

        $fields = [
            ['avatar', $avatar],
            ['name', $faker->name()],
            ['company', $faker->company],
            ['company_role', 'Administrador'],
            ['phone_number_1', $faker->phoneNumber],
            ['phone_number_2', $faker->phoneNumber],
            ['country_code', self::COUNTRY_CODE],
            ['language', 'es'],
            ['old_password', self::PASSWORD],
            ['password', $password],
            ['password_confirmation', $password],
        ];

        return $fields;
    }

头像”字段是图像或文件,但我有一个错误:

1) Tests\Feature\Users\ProfileTest::testProfileEdit with data set #0 ('avatar', Illuminate\Http\Testing\File Object (...))
Session has unexpected error: avatar
Failed asserting that true is false.
4

1 回答 1

0

好的,修好了!问题是File::create方法。必须:

$avatar = UploadedFile::fake()->image('avatar.jpg');
于 2020-04-20T10:39:04.413 回答