Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation to use Zenstruck Foundry instead of Alice #1699

Merged
merged 6 commits into from
May 3, 2023

Conversation

loic425
Copy link
Contributor

@loic425 loic425 commented Jan 20, 2023

No description provided.

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

distribution/testing.md Outdated Show resolved Hide resolved
```console
docker compose exec php \
composer require --dev maker
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split the two calls to maker in two separate commands for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYM

Do you mean these calls?
bin/console make:factory 'App\Entity\Book' &&
bin/console make:factory 'App\Entity\Review'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just two lines:

$ bin/console make:factory 'App\Entity\Book'
$ bin/console make:factory 'App\Entity\Review'

'book' => BookFactory::randomOrCreate(),
'publicationDate' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
'rating' => self::faker()->numberBetween(0, 5),
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

distribution/testing.md Show resolved Hide resolved
distribution/testing.md Show resolved Hide resolved
@alanpoulain
Copy link
Member

Can't we keep Alice too?

@OskarStark
Copy link
Contributor

Friendly ping @kbond @nikophil

@dunglas
Copy link
Member

dunglas commented Jan 22, 2023

@alanpoulain we could keep Alice's documentation in another file, but we should make it crystal clear that we recommend Foundry, as Symfony.

distribution/testing.md Outdated Show resolved Hide resolved
```console
docker compose exec php \
composer require --dev maker
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just two lines:

$ bin/console make:factory 'App\Entity\Book'
$ bin/console make:factory 'App\Entity\Review'

```

Thanks to Symfony Flex, Alice (and [AliceBundle](https://github.com/theofidry/AliceBundle)) are ready to use!
Place your data fixtures files in a directory named `fixtures/`.
And, install [Symfony/MakerBundle](https://github.com/symfony/maker-bundle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MakerBundle is installed with the distribution.

distribution/testing.md Show resolved Hide resolved
loic425 and others added 2 commits January 23, 2023 08:48
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
distribution/testing.md Outdated Show resolved Hide resolved
@loic425
Copy link
Contributor Author

loic425 commented Apr 26, 2023

@dunglas I did the suggested changes

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Here are some minor comments.

distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
distribution/testing.md Outdated Show resolved Hide resolved
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Kevin Bond <kevinbond@gmail.com>
return [
'author' => self::faker()->name(),
'body' => self::faker()->text(),
'book' => lazy(fn() => BookFactory::randomOrCreate()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbond Thank you for your answer, I use your lazy function to create exactly 100 books first and create 30 reviews with random books from the database.
I was not aware of this lazy function or just read too fast this part of the documentation, that's very interesting, thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But indeed, I could also do that in the DefaultReviewsStory:

ReviewFactory::new()
    ->withAttributes(['book' => BookFactory::randomOrCreate(),
    ->many(200)
    ->create()
;

@dunglas dunglas merged commit 26aaf47 into api-platform:3.0 May 3, 2023
1 check passed
@dunglas
Copy link
Member

dunglas commented May 3, 2023

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants