Provider
5 years ago
Factory.php
5 years ago
FactoryContract.php
5 years ago
MetaRepository.php
5 years ago
ProviderForwarder.php
5 years ago
Factory.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\TestData\Framework; |
| 4 | |
| 5 | use Faker\Generator; |
| 6 | |
| 7 | abstract class Factory implements FactoryContract { |
| 8 | use ProviderForwarder; |
| 9 | |
| 10 | /** @var Generator */ |
| 11 | protected $faker; |
| 12 | |
| 13 | public function __construct( Generator $faker ) { |
| 14 | $this->faker = $faker; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @param int $count |
| 19 | * |
| 20 | * @return \Generator |
| 21 | */ |
| 22 | public function make( $count ) { |
| 23 | for ( $i = 0; $i < $count; $i ++ ) { |
| 24 | yield $this->definition(); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Allways generate consistent data |
| 30 | * |
| 31 | * @param bool $consistent |
| 32 | * |
| 33 | * @return Factory |
| 34 | */ |
| 35 | public function consistent( $consistent = true ) { |
| 36 | if ( $consistent ) { |
| 37 | $this->faker->seed( mt_getrandmax() ); |
| 38 | } |
| 39 | |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | abstract public function definition(); |
| 44 | } |
| 45 |