mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Optimized fixtures
This commit is contained in:
parent
4066634af2
commit
e16f2a44a8
19
application/src/DBAL/Types/SystemSlugType.php
Normal file
19
application/src/DBAL/Types/SystemSlugType.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DBAL\Types;
|
||||||
|
|
||||||
|
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Containes the system slugs.
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
final class SystemSlugType extends AbstractEnumType
|
||||||
|
{
|
||||||
|
public const IMPRINT = 'IMPRINT';
|
||||||
|
|
||||||
|
protected static $choices = [
|
||||||
|
self::IMPRINT => 'imprint',
|
||||||
|
];
|
||||||
|
}
|
@ -6,21 +6,31 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
|
|||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use FOS\UserBundle\Doctrine\UserManager;
|
use FOS\UserBundle\Doctrine\UserManager;
|
||||||
|
use App\Entity\UserInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Never execute this fixture on a livesystem!
|
* Never execute this fixture on a livesystem!
|
||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
class DummyFixtures extends Fixture
|
class DummyFixtures extends Fixture implements ContainerAwareInterface
|
||||||
{
|
{
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
public function setContainer(ContainerInterface $container = null)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$this->addTestUser();
|
$manager->persist($this->getTestUser());
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addTestUser(): void
|
protected function getTestUser(): UserInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var UserManager
|
* @var UserManager
|
||||||
@ -35,5 +45,7 @@ class DummyFixtures extends Fixture
|
|||||||
$testUser->setPlainPassword('test');
|
$testUser->setPlainPassword('test');
|
||||||
$testUser->setEnabled(true);
|
$testUser->setEnabled(true);
|
||||||
$userManager->updateUser($testUser);
|
$userManager->updateUser($testUser);
|
||||||
|
|
||||||
|
return $testUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
application/src/DataFixtures/SourceFixtures.php
Normal file
27
application/src/DataFixtures/SourceFixtures.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
use App\Entity\Source\Primitive\Text\TextSource;
|
||||||
|
use App\Entity\Source\Primitive\Text\TextSourceInterface;
|
||||||
|
use App\DBAL\Types\SystemSlugType;
|
||||||
|
|
||||||
|
class SourceFixtures extends Fixture
|
||||||
|
{
|
||||||
|
public function load(ObjectManager $manager)
|
||||||
|
{
|
||||||
|
$manager->persist($this->getImpressum());
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getImpressum(): TextSourceInterface
|
||||||
|
{
|
||||||
|
$source = new TextSource();
|
||||||
|
$source->setText('Example Impressum');
|
||||||
|
$source->setSlug(SystemSlugType::IMPRINT);
|
||||||
|
|
||||||
|
return $source;
|
||||||
|
}
|
||||||
|
}
|
33
application/tests/Integration/FixturesIntegrationTest.php
Normal file
33
application/tests/Integration/FixturesIntegrationTest.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Integration;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use App\Entity\Source\AbstractSource;
|
||||||
|
use App\DBAL\Types\SystemSlugType;
|
||||||
|
use App\Entity\Source\Primitive\Text\TextSourceInterface;
|
||||||
|
|
||||||
|
class FixturesIntegrationTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var EntityManager
|
||||||
|
*/
|
||||||
|
protected $entityManager;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$this->entityManager = static::$kernel->getContainer()->get('doctrine')->getManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testImpressum(): void
|
||||||
|
{
|
||||||
|
$sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
|
||||||
|
/**
|
||||||
|
* @var TextSourceInterface
|
||||||
|
*/
|
||||||
|
$imprint = $sourceRepository->findOneBy(['slug' => SystemSlugType::IMPRINT]);
|
||||||
|
$this->assertInternalType('string', $imprint->getText());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user