We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
When generating fake text in PHP unit tests using faker, I tend to do something like this:
$fakeText = fake()->text(191);
My initial assumption was that this always creates a string of 191 characters. That's is actually not the case.
If you check the documentation, you'll read:
Generate a random string of text. The first parameter represents the maximum number of characters the text should contain (by default,
200
).
The number doesn't indicate how many characters the result will contain, but indicates the maximum amount characters that can be returned.
If you want to have a string of exactly the specified length (to e.g. test validation rules), you are better with using this approach:
Str::random(191);
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.