nelmio / alice

Expressive fixtures generator
MIT License
2.5k stars 329 forks source link

Random number of paragraphs #55

Closed mdavis1982 closed 11 years ago

mdavis1982 commented 11 years ago

In an entity, I have a text field that I use to store biographies of people. These are plain text and need to be multiple paragraphs. I saw the paragraphs() provider in the Faker documentation and thought I would be able to use that, but wanted a random number of them.

So, for example:

biography: <paragraphs(3)>

This doesn't work because it returns 3 separate strings, and I needed a single string concatenated with newlines.

I also wanted to have a random number of these so I tried:

biography: <paragraphs(<numberBetween(0, 4)>)>

That also doesn't work because it isn't parsed correctly. I also tried:

biography: <numberBetween(0, 4)>x <paragraphs(1)>

But that puts 3x lorem... into the column in the database. Is it possible to have a random number of paragraphs, separated by newlines added to a field?

mdavis1982 commented 11 years ago

Would it be possible to do something like:

biography: <paragraphs({1-10})>

For a random number between 1 and 10 paragraphs?

Seldaek commented 11 years ago

The stuff inside () in provider calls is pretty much php run through eval, so I believe you can do <paragraphs(rand(0, 4))>.

mdavis1982 commented 11 years ago

You can...

But that's not what I'm asking. Ideally, I want to have multiple paragraphs, separated by newlines as a single string. That doesn't seems to be possible?

Imagine, for example, an article that you want to fake. That would have lots of text (paragraphs) all separated by newlines. It doesn't seem to be possible to actually do this with Alice?

Baachi commented 11 years ago

@mdavis1982 Use this

biography: <paragraphs(4, true)>