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

@@ -24,20 +24,20 @@ trait LoadAbstractNotificationsTrait
return;
foreach ($this->notifs as $notif) {
$entityId = $this->getReference($notif['entityRef'], null)->getId();
$entityId = $this->getReference($notif['entityRef'], Notification::class)->getId();
echo 'Adding notification for '.$notif['entityClass'].'(entity id:'.$entityId.")\n";
$newNotif = (new Notification())
->setMessage($notif['message'])
->setSender($this->getReference($notif['sender'], null))
->setSender($this->getReference($notif['sender'], Notification::class))
->setRelatedEntityClass($notif['entityClass'])
->setRelatedEntityId($entityId)
->setDate(new \DateTimeImmutable('now'))
->setRead([]);
foreach ($notif['addressees'] as $addressee) {
$newNotif->addAddressee($this->getReference($addressee, null));
$newNotif->addAddressee($this->getReference($addressee, Notification::class));
}
$manager->persist($newNotif);

View File

@@ -13,6 +13,7 @@ namespace Chill\MainBundle\DataFixtures\ORM;
use Chill\MainBundle\Doctrine\Model\Point;
use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Entity\PostalCode;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -70,7 +71,7 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt
$ar->setPoint($this->getRandomPoint());
$ar->setPostcode($this->getReference(
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)],
null
PostalCode::class
));
$ar->setMunicipalityCode($ar->getPostcode()->getCode());

View File

@@ -11,7 +11,9 @@ declare(strict_types=1);
namespace Chill\MainBundle\DataFixtures\ORM;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\Entity\PermissionsGroup;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -30,8 +32,8 @@ class LoadGroupCenters extends AbstractFixture implements OrderedFixtureInterfac
foreach (LoadCenters::$refs as $centerRef) {
foreach (LoadPermissionsGroup::$refs as $permissionGroupRef) {
$GroupCenter = new GroupCenter();
$GroupCenter->setCenter($this->getReference($centerRef, null));
$GroupCenter->setPermissionsGroup($this->getReference($permissionGroupRef, null));
$GroupCenter->setCenter($this->getReference($centerRef, Center::class));
$GroupCenter->setPermissionsGroup($this->getReference($permissionGroupRef, PermissionsGroup::class));
$manager->persist($GroupCenter);

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\DataFixtures\ORM;
use Chill\MainBundle\Entity\PermissionsGroup;
use Chill\MainBundle\Entity\RoleScope;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -59,7 +60,7 @@ class LoadPermissionsGroup extends AbstractFixture implements OrderedFixtureInte
$permissionGroup->setName($new['name']);
foreach ($new['role_scopes'] as $roleScopeRef) {
$permissionGroup->addRoleScope($this->getReference($roleScopeRef, null));
$permissionGroup->addRoleScope($this->getReference($roleScopeRef, RoleScope::class));
}
$manager->persist($permissionGroup);

View File

@@ -365,7 +365,7 @@ class LoadPostalCodes extends AbstractFixture implements OrderedFixtureInterface
$manager->persist($c);
$ref = 'postal_code_'.$code[0];
if (!$this->hasReference($ref, null)) {
if (!$this->hasReference($ref, PostalCode::class)) {
$this->addReference($ref, $c);
self::$refs[] = $ref;
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\DataFixtures\ORM;
use Chill\MainBundle\Entity\RoleScope;
use Chill\MainBundle\Entity\Scope;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -55,8 +56,8 @@ class LoadRoleScopes extends AbstractFixture implements OrderedFixtureInterface
foreach (LoadScopes::$references as $scopeReference) {
$roleScope = new RoleScope();
$roleScope->setRole($key)
->setScope($this->getReference($scopeReference, null));
$reference = 'role_scope_'.$key.'_'.$this->getReference($scopeReference, null)->getName()['en'];
->setScope($this->getReference($scopeReference, Scope::class));
$reference = 'role_scope_'.$key.'_'.$this->getReference($scopeReference, Scope::class)->getName()['en'];
echo "Creating {$reference} \n";
$this->addReference($reference, $roleScope);
$manager->persist($roleScope);

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\DataFixtures\ORM;
use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\Entity\User;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
@@ -80,7 +81,7 @@ class LoadUsers extends AbstractFixture implements ContainerAwareInterface, Orde
->setEmail(sprintf('%s@chill.social', \str_replace(' ', '', (string) $username)));
foreach ($params['groupCenterRefs'] as $groupCenterRef) {
$user->addGroupCenter($this->getReference($groupCenterRef, null));
$user->addGroupCenter($this->getReference($groupCenterRef, GroupCenter::class));
}
echo 'Creating user '.$username."... \n";