Pass class as second parameter to getReference() fixture method

This commit is contained in:
2024-11-28 13:28:52 +01:00
parent 19e6ceba28
commit f820273dd7
27 changed files with 94 additions and 59 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\ReportBundle\DataFixtures\ORM;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -74,7 +75,7 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
->setOptions($cFType['options'])
->setName(['fr' => "CustomField {$i}"])
->setOrdering(random_int(0, 1000) / 1000)
->setCustomFieldsGroup($this->getReference('cf_group_report_'.random_int(0, 3), null));
->setCustomFieldsGroup($this->getReference('cf_group_report_'.random_int(0, 3), CustomFieldsGroup::class));
$manager->persist($customField);
}
@@ -87,7 +88,7 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
private function createExpectedFields(ObjectManager $manager)
{
// report logement
$reportLogement = $this->getReference('cf_group_report_logement', null);
$reportLogement = $this->getReference('cf_group_report_logement', CustomFieldsGroup::class);
$houseTitle = (new CustomField())
->setSlug('house_title')
@@ -143,7 +144,7 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
$manager->persist($descriptionLogement);
// report problems
$reportEducation = $this->getReference('cf_group_report_education', null);
$reportEducation = $this->getReference('cf_group_report_education', CustomFieldsGroup::class);
$title = (new CustomField())
->setSlug('title')

View File

@@ -13,7 +13,9 @@ namespace Chill\ReportBundle\DataFixtures\ORM;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\Entity\PermissionsGroup;
use Chill\MainBundle\Entity\RoleScope;
use Chill\MainBundle\Entity\Scope;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -32,11 +34,11 @@ class LoadReportACL extends AbstractFixture implements OrderedFixtureInterface
public function load(ObjectManager $manager): void
{
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
$permissionsGroup = $this->getReference($permissionsGroupRef, null);
$permissionsGroup = $this->getReference($permissionsGroupRef, PermissionsGroup::class);
printf("processing permission group %s \n", $permissionsGroup->getName());
foreach (LoadScopes::$references as $scopeRef) {
$scope = $this->getReference($scopeRef, null);
$scope = $this->getReference($scopeRef, Scope::class);
printf("processing scope %s \n", $scope->getName()['en']);
// create permission group
switch ($permissionsGroup->getName()) {

View File

@@ -12,8 +12,11 @@ declare(strict_types=1);
namespace Chill\ReportBundle\DataFixtures\ORM;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use Chill\ReportBundle\Entity\Report;
use Doctrine\Common\DataFixtures\AbstractFixture;
@@ -60,9 +63,9 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
if (null !== $charline) {
$report = (new Report())
->setPerson($charline)
->setCFGroup($this->getReference('cf_group_report_logement', null))
->setCFGroup($this->getReference('cf_group_report_logement', CustomFieldsGroup::class))
->setDate(new \DateTime('2015-01-05'))
->setScope($this->getReference('scope_social', null));
->setScope($this->getReference('scope_social', Scope::class));
$this->fillReport($report);
$manager->persist($report);
@@ -81,8 +84,8 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
->setPerson($person)
->setCFGroup(
random_int(0, 10) > 5 ?
$this->getReference('cf_group_report_logement', null) :
$this->getReference('cf_group_report_education', null)
$this->getReference('cf_group_report_logement', CustomFieldsGroup::class) :
$this->getReference('cf_group_report_education', CustomFieldsGroup::class)
)
->setScope($this->getScopeRandom());
$this->fillReport($report);
@@ -95,7 +98,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
// setUser
$usernameRef = array_rand(LoadUsers::$refs);
$report->setUser(
$this->getReference($usernameRef, null)
$this->getReference($usernameRef, User::class)
);
// set date if null
@@ -214,7 +217,7 @@ final class LoadReports extends AbstractFixture implements OrderedFixtureInterfa
{
$ref = LoadScopes::$references[array_rand(LoadScopes::$references)];
return $this->getReference($ref, null);
return $this->getReference($ref, Scope::class);
}
/**