From 2655848d96be967f395539648f2b62bf18f45ef4 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Wed, 25 Dec 2024 02:48:32 +0000 Subject: [PATCH] Add environment variables for data creation for testing --- src/DataFixtures/MemberCaseFixture.php | 6 ++++-- src/DataFixtures/MemberFixture.php | 6 ++++-- src/DataFixtures/NoteFixture.php | 6 ++++-- src/DataFixtures/ReferralFixture.php | 6 ++++-- src/DataFixtures/ReferralSourceFixture.php | 6 ++++-- src/DataFixtures/StaffNoteFixture.php | 3 +++ src/DataFixtures/UserFixture.php | 6 ++++-- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/DataFixtures/MemberCaseFixture.php b/src/DataFixtures/MemberCaseFixture.php index bfeb9f4..81aeaf9 100644 --- a/src/DataFixtures/MemberCaseFixture.php +++ b/src/DataFixtures/MemberCaseFixture.php @@ -16,13 +16,15 @@ class MemberCaseFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { - return; + if(!$_ENV['CREATE_CASES']) { + return; + } $sources = $manager->getRepository(ReferralSource::class)->findAll(); $users = $manager->getRepository(User::class)->findAll(); $gen = \Faker\Factory::create(); - for ($x = 0; $x < 50; $x++) { + for ($x = 0; $x < $_ENV['CREATE_CASES']; $x++) { $case = new MemberCase(); $case->setCaseNumber($gen->numberBetween(1000000, 9999999)) ->setDcsCaseId($gen->numberBetween(1000000, 9999999)) diff --git a/src/DataFixtures/MemberFixture.php b/src/DataFixtures/MemberFixture.php index 42df05a..8bc4c18 100644 --- a/src/DataFixtures/MemberFixture.php +++ b/src/DataFixtures/MemberFixture.php @@ -16,7 +16,9 @@ class MemberFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { - return; + if (!$_ENV['CREATE_MEMBERS']) { + return; + } $gen = \Faker\Factory::create(); $cases = $manager->getRepository(MemberCase::class)->findAll(); @@ -24,7 +26,7 @@ class MemberFixture extends Fixture implements DependentFixtureInterface /** @var MemberCase $case */ $caseLastName = $case->getLastName(); print "Adding members for case {$case->getCaseName()}".PHP_EOL; - $memCount = $gen->numberBetween(0, 5); + $memCount = $gen->numberBetween(0, $_ENV['CREATE_MEMBERS']); for ($x = 0; $x < $memCount; $x++) { $isChild = $gen->boolean(); $isParent = ($isChild ? false : $gen->boolean()); diff --git a/src/DataFixtures/NoteFixture.php b/src/DataFixtures/NoteFixture.php index 6ffdb68..dd4ed1c 100644 --- a/src/DataFixtures/NoteFixture.php +++ b/src/DataFixtures/NoteFixture.php @@ -19,14 +19,16 @@ class NoteFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { - return; + if(!$_ENV['CREATE_NOTES']) { + return; + } $gen = \Faker\Factory::create(); $refs = $manager->getRepository(Referral::class)->findAll(); foreach ($refs as $ref) { /** @var Referral $ref */ print "Adding notes for referral {$ref->getReferralId()}".PHP_EOL; - $noteCount = $gen->numberBetween(0, 10); + $noteCount = $gen->numberBetween(0, $_ENV['CREATE_NOTES']); $case = $ref->getMemberCase(); $caseMembers = $case->getMembers(); diff --git a/src/DataFixtures/ReferralFixture.php b/src/DataFixtures/ReferralFixture.php index 268fbcd..7408ab1 100644 --- a/src/DataFixtures/ReferralFixture.php +++ b/src/DataFixtures/ReferralFixture.php @@ -13,13 +13,15 @@ class ReferralFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { - return; + if(!$_ENV['CREATE_REFERRALS']) { + return; + } $gen = \Faker\Factory::create(); $cases = $manager->getRepository(MemberCase::class)->findAll(); foreach ($cases as $case) { print "Adding referrals for case {$case->getCaseNumber()}".PHP_EOL; - $refCount = $gen->numberBetween(0, 2); + $refCount = $gen->numberBetween(0, $_ENV['CREATE_REFERRALS']); for ($x = 0; $x < $refCount; $x++) { $ref = new Referral(); $ref->setReferralId($gen->numberBetween(1000000, 9999999)) diff --git a/src/DataFixtures/ReferralSourceFixture.php b/src/DataFixtures/ReferralSourceFixture.php index 46f6007..fb45bba 100644 --- a/src/DataFixtures/ReferralSourceFixture.php +++ b/src/DataFixtures/ReferralSourceFixture.php @@ -12,10 +12,12 @@ class ReferralSourceFixture extends Fixture { public function load(ObjectManager $manager): void { - return; + if(!$_ENV['CREATE_SOURCES']) { + return; + } $gen = Factory::create(); - for ($x = 0; $x < 20; $x++) { + for ($x = 0; $x < $_ENV['CREATE_REFERRALS']; $x++) { $src = new ReferralSource(); $name = "{$gen->firstName()} {$gen->lastName()}"; $username = strtolower(str_replace(' ', '.', $name)); diff --git a/src/DataFixtures/StaffNoteFixture.php b/src/DataFixtures/StaffNoteFixture.php index 14eae9c..bc7248e 100644 --- a/src/DataFixtures/StaffNoteFixture.php +++ b/src/DataFixtures/StaffNoteFixture.php @@ -14,6 +14,9 @@ class StaffNoteFixture extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { + if(!$_ENV['CREATE_STAFF_NOTES']) { + return; + } $cases = $manager->getRepository(MemberCase::class)->findAll(); $gen = \Faker\Factory::create(); diff --git a/src/DataFixtures/UserFixture.php b/src/DataFixtures/UserFixture.php index 37b96a2..572ed20 100644 --- a/src/DataFixtures/UserFixture.php +++ b/src/DataFixtures/UserFixture.php @@ -20,10 +20,12 @@ class UserFixture extends Fixture public function load(ObjectManager $manager): void { - return; + if(!$_ENV['CREATE_USERS']) { + return; + } $comp = $manager->getRepository(Company::class)->findOneBy(['name' => 'Counseling Partners, LLC']); $gen = \Faker\Factory::create(); - for ($x = 0; $x < 20; $x++) { + for ($x = 0; $x < $_ENV['CREATE_USERS']; $x++) { $user = new User(); $name = $gen->firstName().' '.$gen->lastName(); $username = strtolower(str_replace(' ', '.', $name));