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

Story pools #252

Merged
merged 2 commits into from
Mar 7, 2022
Merged

Story pools #252

merged 2 commits into from
Mar 7, 2022

Conversation

kbond
Copy link
Member

@kbond kbond commented Feb 10, 2022

Closes #250.

Adds the following API to Story's:

final class ProvinceStory extends Story
{
    public function build(): void
    {
        // add collection to a "pool"
        $this->addToPool('be', ProvinceFactory::createMany(5, ['country' => 'BE']));

        // equivalent to above
        $this->addToPool('be', ProvinceFactory::new(['country' => 'BE'])->many(5));

        // add single object to a pool
        $this->addToPool('be', ProvinceFactory::createOne(['country' => 'BE']));

        // add single object to single pool and make available as "state"
        $this->addState('be-1', ProvinceFactory::createOne(['country' => 'BE']), 'be');
    }
}

Usage:

ProvinceStory::getRandom('be'); // random Proxy from "be" pool
ProvinceStory::getRandomSet('be', 3); // 3 random Proxy's from "be" pool
ProvinceStory::getRandomRange('be', 1, 4); // between 1 and 4 random Proxy's from "be" pool

TODO:

  • Tests
  • Docs

@kbond kbond added the enhancement New feature or request label Feb 10, 2022
src/Story.php Outdated Show resolved Hide resolved
src/Story.php Show resolved Hide resolved
@kbond kbond force-pushed the story-pools branch 3 times, most recently from b76f808 to 17aec97 Compare March 4, 2022 16:06
@kbond
Copy link
Member Author

kbond commented Mar 4, 2022

I believe this to be ready, @jmsche, @wouterj: mind giving a final review?

docs/index.rst Outdated Show resolved Hide resolved
src/Story.php Outdated Show resolved Hide resolved
src/Story.php Outdated Show resolved Hide resolved
@kbond
Copy link
Member Author

kbond commented Mar 7, 2022

Thanks for the review @jmsche! Would you say this adequately solves #250 for you?

@jmsche
Copy link
Contributor

jmsche commented Mar 7, 2022

Would you say this adequately solves #250 for you?

Yes, I think it should solve this issue.

Thanks for the review @jmsche!

And thank you for everything :)

@kbond kbond merged commit 4a56be7 into zenstruck:master Mar 7, 2022
@kbond kbond deleted the story-pools branch March 7, 2022 14:39
@jmsche
Copy link
Contributor

jmsche commented Mar 24, 2022

Hi Kevin, do you think you can create a new release including this new feature? Or are you waiting to finish an other PR first?

@kbond
Copy link
Member Author

kbond commented Mar 24, 2022

Done! https://github.com/zenstruck/foundry/releases/tag/v1.17.0

@jmsche
Copy link
Contributor

jmsche commented Mar 24, 2022

Thank you for your fast reaction :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

Random "named"/"prefixed" references
3 participants