2018-11-03 15:53:05 +01:00
|
|
|
<?php
|
2018-11-04 11:36:40 +01:00
|
|
|
|
2019-02-17 14:33:19 +01:00
|
|
|
namespace Infinito\DataFixtures;
|
2018-11-03 15:53:05 +01:00
|
|
|
|
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
|
|
use Doctrine\Common\Persistence\ObjectManager;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\User;
|
2018-11-23 19:10:24 +01:00
|
|
|
use FOS\UserBundle\Doctrine\UserManager;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\UserInterface;
|
2018-11-23 22:09:29 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
2018-11-04 11:36:40 +01:00
|
|
|
|
2018-11-04 11:53:36 +01:00
|
|
|
/**
|
|
|
|
* Never execute this fixture on a livesystem!
|
|
|
|
*
|
2018-11-04 12:25:53 +01:00
|
|
|
* @author kevinfrantz
|
2018-11-04 11:53:36 +01:00
|
|
|
*/
|
2018-11-23 22:09:29 +01:00
|
|
|
class DummyFixtures extends Fixture implements ContainerAwareInterface
|
2018-11-03 15:53:05 +01:00
|
|
|
{
|
2018-11-23 22:09:29 +01:00
|
|
|
private $container;
|
|
|
|
|
|
|
|
public function setContainer(ContainerInterface $container = null)
|
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
}
|
|
|
|
|
2018-11-03 15:53:05 +01:00
|
|
|
public function load(ObjectManager $manager)
|
|
|
|
{
|
2018-11-23 22:09:29 +01:00
|
|
|
$manager->persist($this->getTestUser());
|
2018-11-23 19:10:24 +01:00
|
|
|
$manager->flush();
|
2018-11-03 15:53:05 +01:00
|
|
|
}
|
2018-11-23 19:29:49 +01:00
|
|
|
|
2018-11-23 22:09:29 +01:00
|
|
|
protected function getTestUser(): UserInterface
|
2018-11-23 19:29:49 +01:00
|
|
|
{
|
2018-11-23 19:10:24 +01:00
|
|
|
/**
|
2018-11-23 19:29:49 +01:00
|
|
|
* @var UserManager
|
2018-11-23 19:10:24 +01:00
|
|
|
*/
|
|
|
|
$userManager = $this->container->get('fos_user.user_manager');
|
|
|
|
/**
|
2018-11-23 19:29:49 +01:00
|
|
|
* @var User
|
2018-11-23 19:10:24 +01:00
|
|
|
*/
|
|
|
|
$testUser = $userManager->createUser();
|
2018-11-23 19:29:49 +01:00
|
|
|
$testUser->setEmail('test@test.de');
|
|
|
|
$testUser->setUsername('test');
|
2018-11-23 19:10:24 +01:00
|
|
|
$testUser->setPlainPassword('test');
|
|
|
|
$testUser->setEnabled(true);
|
|
|
|
$userManager->updateUser($testUser);
|
2018-11-23 22:09:29 +01:00
|
|
|
|
|
|
|
return $testUser;
|
2018-11-03 15:53:05 +01:00
|
|
|
}
|
2018-11-04 11:36:40 +01:00
|
|
|
}
|