laraveltestingphpunitfaker

laravel testing with faker big text


I'm testing a form where user must introduce some text between let's say 100 and 500 characters.

I tried to emulate the user input:

$this->actingAs($user)
->visit('myweb/create')
->type($this->faker->text(1000),'description')
->press('Save')
->see('greater than');

But it seems that faker is creating a quite smaller text so the test does not pass.

In fact, the param specifies the max number of characters, not the minimum. How can I tell faker the minimum?


Solution

  • The Faker API does not provide you with an option to set the minimum number of characters. So you better use something else, for example Laravel's str_random(1000) helper function will create a string consisting of exactly 1000 characters.