From 60094990d082308b7adaf7b57e30b7ecb80ad1be Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 20 Jun 2022 09:49:14 -0400 Subject: [PATCH] [feature] add `Story::getPool()` (#282) --- docs/index.rst | 1 + src/Story.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 0259a34d3..096f49099 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1731,6 +1731,7 @@ Objects can be fetched from pools in your tests, fixtures or other stories: ProvinceStory::getRandom('be'); // random Province|Proxy from "be" pool ProvinceStory::getRandomSet('be', 3); // 3 random Province|Proxy's from "be" pool ProvinceStory::getRandomRange('be', 1, 4); // between 1 and 4 random Province|Proxy's from "be" pool + ProvinceStory::getPool('be'); // all Province|Proxy's from "be" pool Bundle Configuration -------------------- diff --git a/src/Story.php b/src/Story.php index 1388895c6..877689d68 100644 --- a/src/Story.php +++ b/src/Story.php @@ -31,6 +31,16 @@ final public static function load(): self return Factory::configuration()->stories()->load(static::class); } + /** + * Get all the items in a pool. + * + * @return Proxy[] + */ + final public static function getPool(string $pool): array + { + return static::load()->pools[$pool] ?? []; + } + /** * Get a random item from a pool. */ @@ -68,8 +78,7 @@ final public static function getRandomRange(string $pool, int $min, int $max): a throw new \InvalidArgumentException(\sprintf('$max (%d) cannot be less than $min (%d).', $max, $min)); } - $story = static::load(); - $values = $story->pools[$pool] ?? []; + $values = static::getPool($pool); \shuffle($values);