mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
dataFixtures fixed and executed + start of test script
This commit is contained in:
parent
5512e25cdf
commit
db92531257
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
||||||
|
|
||||||
|
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||||
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use Faker\Factory as FakerFactory;
|
||||||
|
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
||||||
|
use Chill\AsideActivityBundle\DataFixtures\ORM\LoadAsideActivityCategory;
|
||||||
|
use Chill\AsideActivityBundle\Entity\AsideActivity;
|
||||||
|
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
|
use DateTime;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
||||||
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load reports into DB
|
||||||
|
*
|
||||||
|
* @author Champs-Libres Coop
|
||||||
|
*/
|
||||||
|
class LoadAsideActivity extends AbstractFixture implements DependentFixtureInterface, ContainerAwareInterface
|
||||||
|
{
|
||||||
|
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Faker\Generator
|
||||||
|
*/
|
||||||
|
private $faker;
|
||||||
|
|
||||||
|
private array $cacheUsers = [];
|
||||||
|
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->faker = FakerFactory::create('fr_FR');
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDependencies()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
LoadAsideActivityCategory::class,
|
||||||
|
LoadUsers::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random asideActivityCategory
|
||||||
|
*
|
||||||
|
* @return \Chill\AsideActivityBundle\Entity\AsideActivityCategory
|
||||||
|
*/
|
||||||
|
private function getRandomAsideActivityCategory(): AsideActivityCategory
|
||||||
|
{
|
||||||
|
$catRef = LoadAsideActivityCategory::$references[array_rand(LoadAsideActivityCategory::$references)];
|
||||||
|
|
||||||
|
return $this->getReference($catRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random user
|
||||||
|
*
|
||||||
|
* @return \Chill\MainBundle\Entity\User
|
||||||
|
*/
|
||||||
|
private function getRandomUser(): User
|
||||||
|
{
|
||||||
|
if (0 === count($this->cacheUsers)){
|
||||||
|
$this->cacheUsers = $this->container->get('doctrine.orm.entity_manager')
|
||||||
|
->getRepository('ChillMainBundle:User')
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cacheUsers[array_rand($this->cacheUsers)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newRandomActivity()
|
||||||
|
{
|
||||||
|
$asideactivity = ($activity = new AsideActivity())
|
||||||
|
->setAgent($this->getRandomUser())
|
||||||
|
->setDate($this->faker->dateTimeThisYear())
|
||||||
|
->setCreatedAt(new DateTime())
|
||||||
|
->setCreatedBy($activity->getAgent())
|
||||||
|
//->setDuration(3600)
|
||||||
|
->setType($this->getRandomAsideActivityCategory());
|
||||||
|
|
||||||
|
return $asideactivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager)
|
||||||
|
{
|
||||||
|
for($i = 0; $i < 100; $i ++) {
|
||||||
|
$asideactivity = $this->newRandomActivity();
|
||||||
|
$manager->persist($asideactivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
Namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
||||||
|
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
|
||||||
|
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
||||||
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixtures for AsideActivityCategory
|
||||||
|
*
|
||||||
|
* @author Champs-Libres Coop
|
||||||
|
*/
|
||||||
|
class LoadAsideActivityCategory extends Fixture
|
||||||
|
{
|
||||||
|
public static $references = array();
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager)
|
||||||
|
{
|
||||||
|
$categories = [
|
||||||
|
[
|
||||||
|
'title' => ['fr' => 'Formation', 'en' => 'Training'],
|
||||||
|
'ref' => 'training',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'title' => ['fr' => 'Team building', 'en' => 'Team building'],
|
||||||
|
'ref' => 'teambuilding',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($categories as $cat) {
|
||||||
|
print "Creating aside activity type category : " . $cat['ref'] . "\n";
|
||||||
|
|
||||||
|
$newCat = (new AsideActivityCategory())
|
||||||
|
->setTitle(($cat['title']));
|
||||||
|
|
||||||
|
$manager->persist($newCat);
|
||||||
|
$reference = 'activity_type_cat_'.$cat['ref'];
|
||||||
|
|
||||||
|
$this->addReference($reference, $newCat);
|
||||||
|
static::$references[] = $reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ final class ChillAsideActivityExtension extends Extension implements PrependExte
|
|||||||
public function load(array $configs, ContainerBuilder $container): void
|
public function load(array $configs, ContainerBuilder $container): void
|
||||||
{
|
{
|
||||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||||
// $loader->load('services.yaml');
|
$loader->load('services.yaml');
|
||||||
$loader->load('services/form.yaml');
|
$loader->load('services/form.yaml');
|
||||||
$loader->load('services/menu.yaml');
|
$loader->load('services/menu.yaml');
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\AsideActivityBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
|
||||||
|
class AccompanyingCourseControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
use PrepareClientTrait;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
self::bootKernel();
|
||||||
|
$this->client = $this->getClientAuthenticated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNewWithoutUsers()
|
||||||
|
{
|
||||||
|
$this->client->request('GET', '/fr/asideactivity');
|
||||||
|
|
||||||
|
$this->assertResponseSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user