0

I don't know how use the dataProvider for laravel testing with a file field:

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;
    }

The "avatar" field is an image or file, but I have an error:

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.
Marc Garcia
  • 1,388
  • 1
  • 9
  • 21

1 Answers1

0

Okay, fixed! The problem was the File::create method. Has to be:

$avatar = UploadedFile::fake()->image('avatar.jpg');
Marc Garcia
  • 1,388
  • 1
  • 9
  • 21