mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Optimized membership attribute
This commit is contained in:
parent
ce6607fa1a
commit
a64541a9ad
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Entity\Source;
|
namespace App\Entity\Source;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@ -20,6 +19,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
*
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
@ -57,6 +57,7 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
|||||||
protected $slug;
|
protected $slug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @var RelationInterface
|
* @var RelationInterface
|
||||||
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation",cascade={"persist", "remove"})
|
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation",cascade={"persist", "remove"})
|
||||||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", onDelete="CASCADE")
|
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", onDelete="CASCADE")
|
||||||
@ -65,15 +66,25 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
|||||||
protected $relation;
|
protected $relation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Implement that just one table on database level is needed!
|
* Many Sources have many Source Members
|
||||||
* @todo Rename table to use the right schema
|
* @var Collection|SourceInterface[]
|
||||||
|
* @ORM\ManyToMany(targetEntity="AbstractSource", inversedBy="members",cascade={"persist"})
|
||||||
|
* @ORM\JoinTable(name="source_members",
|
||||||
|
* joinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id")},
|
||||||
|
* inverseJoinColumns={@ORM\JoinColumn(name="member_id", referencedColumnName="id")}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
protected $members;
|
||||||
|
|
||||||
|
/**
|
||||||
*
|
*
|
||||||
* @var Collection|TreeCollectionSourceInterface[]
|
* @var Collection|SourceInterface[]
|
||||||
* @ORM\ManyToMany(targetEntity="App\Entity\Source\Complex\Collection\TreeCollectionSource",mappedBy="collection")
|
* @ORM\ManyToMany(targetEntity="AbstractSource",mappedBy="members",cascade={"persist"})
|
||||||
*/
|
*/
|
||||||
protected $memberships;
|
protected $memberships;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Law",cascade={"persist", "remove"})
|
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Law",cascade={"persist", "remove"})
|
||||||
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
|
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
|
||||||
*
|
*
|
||||||
|
12
application/src/Repository/UserSourceRepository.php
Normal file
12
application/src/Repository/UserSourceRepository.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class UserSourceRepository extends EntityRepository
|
||||||
|
{
|
||||||
|
}
|
@ -7,7 +7,7 @@ use Doctrine\ORM\EntityManager;
|
|||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\UserInterface;
|
use App\Entity\UserInterface;
|
||||||
use App\Entity\Source\Combination\PersonIdentitySourceInterface;
|
use App\Entity\Source\Complex\PersonIdentitySourceInterface;
|
||||||
use App\Entity\Source\Complex\PersonIdentitySource;
|
use App\Entity\Source\Complex\PersonIdentitySource;
|
||||||
|
|
||||||
class UserRepositoryTest extends KernelTestCase
|
class UserRepositoryTest extends KernelTestCase
|
||||||
|
103
application/tests/Unit/Repository/UserSourceRepositoryTest.php
Normal file
103
application/tests/Unit/Repository/UserSourceRepositoryTest.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\Unit\Repository;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use App\Entity\UserInterface;
|
||||||
|
use App\Repository\UserSourceRepository;
|
||||||
|
use App\Entity\Source\Complex\UserSourceInterface;
|
||||||
|
use App\Entity\Source\Complex\UserSource;
|
||||||
|
|
||||||
|
class UserSourceRepositoryTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var EntityManager
|
||||||
|
*/
|
||||||
|
protected $entityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var UserSourceRepository
|
||||||
|
*/
|
||||||
|
protected $userSourceRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var UserSourceInterface
|
||||||
|
*/
|
||||||
|
protected $loadedUserSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var UserInterface
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var UserSourceInterface
|
||||||
|
*/
|
||||||
|
protected $userSource;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$kernel = self::bootKernel();
|
||||||
|
$this->entityManager = $kernel->getContainer()
|
||||||
|
->get('doctrine')
|
||||||
|
->getManager();
|
||||||
|
$this->userSourceRepository = $this->entityManager->getRepository(UserSource::class);
|
||||||
|
$this->userSource = new UserSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMemberships(): void
|
||||||
|
{
|
||||||
|
$userSource2 = new UserSource();
|
||||||
|
$this->userSource->getMemberships()->add($userSource2);
|
||||||
|
$this->entityManager->persist($this->userSource);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$userSource2Id = $userSource2->getId();
|
||||||
|
$userSourceId = $this->userSource->getId();
|
||||||
|
$this->loadedUserSource = $this->userSourceRepository->find($userSourceId);
|
||||||
|
$this->assertGreaterThan(0, $userSource2Id);
|
||||||
|
$this->assertEquals($userSource2, $this->loadedUserSource->getMemberships()->get(0));
|
||||||
|
$this->deleteUserSource();
|
||||||
|
$this->assertGreaterThan(0, $userSource2Id);
|
||||||
|
$this->entityManager->remove($userSource2);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->assertNull($this->userSourceRepository->find($userSource2Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreation(): void
|
||||||
|
{
|
||||||
|
$this->entityManager->persist($this->userSource);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$userSourceId = $this->userSource->getId();
|
||||||
|
/*
|
||||||
|
* @var UserSourceInterface
|
||||||
|
*/
|
||||||
|
$this->loadedUserSource = $this->userSourceRepository->find($userSourceId);
|
||||||
|
$this->assertEquals($userSourceId, $this->loadedUserSource->getId());
|
||||||
|
$this->deleteUserSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteUserSource(): void
|
||||||
|
{
|
||||||
|
$this->entityManager->remove($this->loadedUserSource);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
|
||||||
|
*/
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
$this->entityManager->close();
|
||||||
|
$this->entityManager = null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user