brilo-example/tests/Common/FakerTrait.php

28 lines
459 B
PHP
Raw Permalink Normal View History

2024-08-02 12:13:25 +00:00
<?php
declare(strict_types=1);
namespace App\Tests\Common;
use Faker\Factory;
use Faker\Generator;
trait FakerTrait
{
private ?Generator $faker;
protected function bootFaker(): void
{
$this->faker = Factory::create();
}
protected function getFaker(): Generator
{
if ($this->faker === null) {
throw new \LogicException('Faker has not been booted yet.');
}
return $this->faker;
}
}