mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-04 12:03:44 +00:00
Add seeds to data fixtures, to avoid random failures in tests
This commit is contained in:
@@ -35,6 +35,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
) {
|
||||
mt_srand(123456789);
|
||||
$this->faker = FakerFactory::create('fr_FR');
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
||||
$report = (new Report())
|
||||
->setPerson($person)
|
||||
->setCFGroup(
|
||||
random_int(0, 10) > 5 ?
|
||||
mt_rand(0, 10) > 5 ?
|
||||
$this->getReference('cf_group_report_logement', CustomFieldsGroup::class) :
|
||||
$this->getReference('cf_group_report_education', CustomFieldsGroup::class)
|
||||
)
|
||||
@@ -106,7 +107,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
||||
// set date. 30% of the dates are 2015-05-01
|
||||
$expectedDate = new \DateTime('2015-01-05');
|
||||
|
||||
if (random_int(0, 100) < 30) {
|
||||
if (mt_rand(0, 100) < 30) {
|
||||
$report->setDate($expectedDate);
|
||||
} else {
|
||||
$report->setDate($this->faker->dateTimeBetween('-1 year', 'now')
|
||||
@@ -150,7 +151,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
||||
$selectedPeople = [];
|
||||
|
||||
foreach ($people as $person) {
|
||||
if (random_int(0, 100) < $percentage) {
|
||||
if (mt_rand(0, 100) < $percentage) {
|
||||
$selectedPeople[] = $person;
|
||||
}
|
||||
}
|
||||
@@ -178,7 +179,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
|
||||
$picked = [];
|
||||
|
||||
if ($multiple) {
|
||||
$numberSelected = random_int(1, \count($choices) - 1);
|
||||
$numberSelected = mt_rand(1, \count($choices) - 1);
|
||||
|
||||
for ($i = 0; $i < $numberSelected; ++$i) {
|
||||
$picked[] = $this->pickChoice($choices);
|
||||
|
||||
Reference in New Issue
Block a user