Data fixtures

pull/10/head
root 2018-06-04 18:25:58 +02:00
parent d136acc13c
commit 8a0bfedd64
7 changed files with 226 additions and 1 deletions

0
Dockerfile Normal file
View File

View File

@ -5,6 +5,7 @@
"php": "^7.1.3",
"ext-iconv": "*",
"api-platform/api-pack": "^1.1",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/console": "^4.0",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",

123
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "df1fb0339808419998d06c9ecb09ab6f",
"content-hash": "6fb85b3fa57133c433a33fb80ed9c9c6",
"packages": [
{
"name": "api-platform/api-pack",
@ -441,6 +441,66 @@
],
"time": "2017-08-31T08:43:38+00:00"
},
{
"name": "doctrine/data-fixtures",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/data-fixtures.git",
"reference": "3a1e2c3c600e615a2dffe56d4ca0875cc5233e0a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/3a1e2c3c600e615a2dffe56d4ca0875cc5233e0a",
"reference": "3a1e2c3c600e615a2dffe56d4ca0875cc5233e0a",
"shasum": ""
},
"require": {
"doctrine/common": "~2.2",
"php": "^7.1"
},
"conflict": {
"doctrine/phpcr-odm": "<1.3.0"
},
"require-dev": {
"doctrine/dbal": "^2.5.4",
"doctrine/orm": "^2.5.4",
"phpunit/phpunit": "^7.0"
},
"suggest": {
"alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7",
"doctrine/mongodb-odm": "For loading MongoDB ODM fixtures",
"doctrine/orm": "For loading ORM fixtures",
"doctrine/phpcr-odm": "For loading PHPCR ODM fixtures"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Data Fixtures for all Doctrine Object Managers",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"database"
],
"time": "2018-03-20T09:06:36+00:00"
},
{
"name": "doctrine/dbal",
"version": "v2.7.1",
@ -689,6 +749,67 @@
],
"time": "2018-03-27T09:22:12+00:00"
},
{
"name": "doctrine/doctrine-fixtures-bundle",
"version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/doctrine/DoctrineFixturesBundle.git",
"reference": "7fc29d2b18c61ed99826b21fbfd1ff9969cc2e7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/7fc29d2b18c61ed99826b21fbfd1ff9969cc2e7f",
"reference": "7fc29d2b18c61ed99826b21fbfd1ff9969cc2e7f",
"shasum": ""
},
"require": {
"doctrine/data-fixtures": "~1.0",
"doctrine/doctrine-bundle": "~1.0",
"php": ">=5.5.9|^7.0",
"symfony/doctrine-bridge": "~2.7|~3.0|~4.0",
"symfony/framework-bundle": "^3.3|^4.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.3"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Bundle\\FixturesBundle\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
},
{
"name": "Doctrine Project",
"homepage": "http://www.doctrine-project.org"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Symfony DoctrineFixturesBundle",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"Fixture",
"persistence"
],
"time": "2017-12-04T20:26:38+00:00"
},
{
"name": "doctrine/doctrine-migrations-bundle",
"version": "v1.3.1",

View File

@ -12,4 +12,5 @@ return [
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];

0
src/DataFixtures/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,90 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\DataFixtures;
use App\Entity\Question;
use App\Entity\Response;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function __construct()
{
//
}
public function load(ObjectManager $manager)
{
$this->loadQuestions($manager);
//$this->loadResponses($manager);
}
private function loadQuestions(ObjectManager $manager)
{
foreach ($this->getData() as $data) {
$question = new Question();
$question->setText($data['text']);
foreach ($data['responses'] as $response) {
$newResponse = new Response();
$newResponse->setText($response['text']);
$newResponse->setQuestion($question->getId());
$manager->persist($newResponse);
$question->addResponse($newResponse);
}
$manager->persist($question);
//$this->addReference($username, $user);
}
$manager->flush();
}
private function loadResponses(ObjectManager $manager)
{
//
}
private function getData()
{
return [
[
"text" => "ma question 1",
"responses" => [
[
"text" => "option1",
"child" => 1,
],
[
"text" => "option2",
],
]
],
[
"text" => "ma question 2",
"responses" => [
[
"text" => "option1",
],
[
"text" => "option2",
],
[
"text" => "option3",
],
]
]
];
}
}

View File

@ -29,6 +29,9 @@
"doctrine/common": {
"version": "v2.8.1"
},
"doctrine/data-fixtures": {
"version": "v1.3.1"
},
"doctrine/dbal": {
"version": "v2.7.1"
},
@ -44,6 +47,15 @@
"doctrine/doctrine-cache-bundle": {
"version": "1.3.3"
},
"doctrine/doctrine-fixtures-bundle": {
"version": "3.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.0",
"ref": "2ea6070ecf365f9a801ccaed4b31d4a3b7af5693"
}
},
"doctrine/doctrine-migrations-bundle": {
"version": "1.2",
"recipe": {