for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\Foundry;
/**
* @author Kevin Bond <[email protected]>
*/
final class FactoryCollection
{
/** @var Factory */
private $factory;
/** @var int */
private $count;
public function __construct(Factory $factory, int $count)
if ($count < 1) {
throw new \InvalidArgumentException('Count must be greater than 0.');
}
$this->factory = $factory;
$this->count = $count;
* @param array|callable $attributes
*
* @return Proxy[]|object[]
public function create($attributes = []): array
return $this->factory->createMany($this->count, $attributes);
public function createFor(Proxy $proxy): void
$attribute = \lcfirst((new \ReflectionClass($proxy->object()))->getShortName());
$this->create([$attribute => $proxy]);
if ($proxy->isPersisted()) {
$proxy->refresh();