samedi 2 mai 2020

Laravel testing not execute when using trans helper on data provider

I have problem when testing validating using data provider.. When i use translation helper the test not execute but when use normal text (string) the testing run normal...

But i want use translation helper to easy maintenance in future...

Here my example code :

/**
 * @dataProvider validateFirstNameProvider
 */
public function testStoreValidation($attribute, $value, $message)
{
    $response = $this->actingAs($this->user)
        ->post(route('user.store'), [
            $attribute=> $value,
        ]);

    $response->assertSessionHasErrorsIn('validation', [
        $attribute => $message,
    ]);
}

public function validateFirstNameProvider()
{
    return [
        'required first name' => [
            'first_name',
            '',
            trans('validation.required', [
                'attribute' => trans('validation.attributes.first_name'),
            ]),
        ],
    ];
}

Code without use translation helper :

public function validateFirstNameProvider()
{
    return [
        'required first name' => [
            'first_name',
            '',
            'The first name field is required.',
        ],
    ];
}

Aucun commentaire:

Enregistrer un commentaire