How to ask Faker to generate text over $x chars long?
Hello,
Hoping this will be really simple.
I have verification on a field to ensure it is no longer than 500 chars:
'about' => ['required', 'max:500'],
And now I want to write a test that will always go over that limit so I can check the correct error message appears.
How can I ask Faker/Generator to generate random text longer than 500 chars?
Thanks!
Why not just use Str::random(501); ?
Or this should work
$faker->text(501)
@sinnbeck thanks for the fast response.
Yes I can and I will but I was hoping to generate more 'natural' text for some other tests I am doing.
Perhaps I will isolate this test and just do as you suggest and use faker in the other test.
Do you know of a way to ask Faker to generate text/lorem ipsum longer than n?
@sinnbeck oops our messages crossed.
sadly no, even
$faker->text(600),
often generates text shorter than 500 chars so my test is flaky.
Oh didnt know :)
How about adding some way longer then?
$faker->sentence(490);
Yeah I wondered about that too, but wasn't sure if that will always definitely be longer than 500, but I expect it will.
Well a word is at least on character so setting a sentence to 500 words should absolutely do it :) Notice that it isnt max as text is
Please or to participate in this conversation.