Ajout faker et fixture pour question 3

This commit is contained in:
Zakarya BENJABALLAH 2023-02-07 16:55:04 +01:00
parent 7c3e5d17da
commit 78d7a526a9
7 changed files with 294 additions and 1 deletions

View File

@ -34,3 +34,10 @@ symfony console make:entity Atelier # Création d'une entité Atelier
symfony console make:migration # Création d'une migration
symfony console doctrine:migrations:migrate # On lance la migration
```
### Question 3
```bash
symfony composer require fakerphp/faker
symfony composer require orm-fixtures --dev
symfony console doctrine:fixtures:load
```

View File

@ -11,6 +11,7 @@
"doctrine/doctrine-bundle": "^2.8",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.14",
"fakerphp/faker": "^1.21",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.16",
"sensio/framework-extra-bundle": "^6.1",
@ -92,6 +93,7 @@
}
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"phpunit/phpunit": "^10.0",
"symfony/browser-kit": "6.2.*",
"symfony/css-selector": "6.2.*",

235
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6542c2a13eb7352113703fc03b9fbbf5",
"content-hash": "bc632d4e0ebaf53085b8673163075690",
"packages": [
{
"name": "doctrine/annotations",
@ -1456,6 +1456,74 @@
],
"time": "2023-01-14T14:17:03+00:00"
},
{
"name": "fakerphp/faker",
"version": "v1.21.0",
"source": {
"type": "git",
"url": "https://github.com/FakerPHP/Faker.git",
"reference": "92efad6a967f0b79c499705c69b662f738cc9e4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FakerPHP/Faker/zipball/92efad6a967f0b79c499705c69b662f738cc9e4d",
"reference": "92efad6a967f0b79c499705c69b662f738cc9e4d",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"psr/container": "^1.0 || ^2.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"conflict": {
"fzaninotto/faker": "*"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"doctrine/persistence": "^1.3 || ^2.0",
"ext-intl": "*",
"phpunit/phpunit": "^9.5.26",
"symfony/phpunit-bridge": "^5.4.16"
},
"suggest": {
"doctrine/orm": "Required to use Faker\\ORM\\Doctrine",
"ext-curl": "Required by Faker\\Provider\\Image to download images.",
"ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.",
"ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.",
"ext-mbstring": "Required for multibyte Unicode string functionality."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "v1.21-dev"
}
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"support": {
"issues": "https://github.com/FakerPHP/Faker/issues",
"source": "https://github.com/FakerPHP/Faker/tree/v1.21.0"
},
"time": "2022-12-13T13:54:32+00:00"
},
{
"name": "friendsofphp/proxy-manager-lts",
"version": "v1.0.14",
@ -7494,6 +7562,171 @@
}
],
"packages-dev": [
{
"name": "doctrine/data-fixtures",
"version": "1.6.3",
"source": {
"type": "git",
"url": "https://github.com/doctrine/data-fixtures.git",
"reference": "c27821d038e64f1bfc852a94064d65d2a75ad01f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/c27821d038e64f1bfc852a94064d65d2a75ad01f",
"reference": "c27821d038e64f1bfc852a94064d65d2a75ad01f",
"shasum": ""
},
"require": {
"doctrine/persistence": "^1.3.3|^2.0|^3.0",
"php": "^7.2 || ^8.0"
},
"conflict": {
"doctrine/dbal": "<2.13",
"doctrine/orm": "<2.12",
"doctrine/phpcr-odm": "<1.3.0"
},
"require-dev": {
"doctrine/coding-standard": "^10.0",
"doctrine/dbal": "^2.13 || ^3.0",
"doctrine/deprecations": "^1.0",
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
"doctrine/orm": "^2.12",
"ext-sqlite3": "*",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^8.5 || ^9.5",
"symfony/cache": "^5.0 || ^6.0",
"vimeo/psalm": "^4.10"
},
"suggest": {
"alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)",
"doctrine/mongodb-odm": "For loading MongoDB ODM fixtures",
"doctrine/orm": "For loading ORM fixtures",
"doctrine/phpcr-odm": "For loading PHPCR ODM fixtures"
},
"type": "library",
"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": "https://www.doctrine-project.org",
"keywords": [
"database"
],
"support": {
"issues": "https://github.com/doctrine/data-fixtures/issues",
"source": "https://github.com/doctrine/data-fixtures/tree/1.6.3"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdata-fixtures",
"type": "tidelift"
}
],
"time": "2023-01-07T15:10:22+00:00"
},
{
"name": "doctrine/doctrine-fixtures-bundle",
"version": "3.4.2",
"source": {
"type": "git",
"url": "https://github.com/doctrine/DoctrineFixturesBundle.git",
"reference": "601988c5b46dbd20a0f886f967210aba378a6fd5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/601988c5b46dbd20a0f886f967210aba378a6fd5",
"reference": "601988c5b46dbd20a0f886f967210aba378a6fd5",
"shasum": ""
},
"require": {
"doctrine/data-fixtures": "^1.3",
"doctrine/doctrine-bundle": "^1.11|^2.0",
"doctrine/orm": "^2.6.0",
"doctrine/persistence": "^1.3.7|^2.0|^3.0",
"php": "^7.1 || ^8.0",
"symfony/config": "^3.4|^4.3|^5.0|^6.0",
"symfony/console": "^3.4|^4.3|^5.0|^6.0",
"symfony/dependency-injection": "^3.4.47|^4.3|^5.0|^6.0",
"symfony/doctrine-bridge": "^3.4|^4.1|^5.0|^6.0",
"symfony/http-kernel": "^3.4|^4.3|^5.0|^6.0"
},
"require-dev": {
"doctrine/coding-standard": "^9",
"phpstan/phpstan": "^1.4.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20",
"symfony/phpunit-bridge": "^6.0.8",
"vimeo/psalm": "^4.22"
},
"type": "symfony-bundle",
"autoload": {
"psr-4": {
"Doctrine\\Bundle\\FixturesBundle\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Doctrine Project",
"homepage": "https://www.doctrine-project.org"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony DoctrineFixturesBundle",
"homepage": "https://www.doctrine-project.org",
"keywords": [
"Fixture",
"persistence"
],
"support": {
"issues": "https://github.com/doctrine/DoctrineFixturesBundle/issues",
"source": "https://github.com/doctrine/DoctrineFixturesBundle/tree/3.4.2"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdoctrine-fixtures-bundle",
"type": "tidelift"
}
],
"time": "2022-04-28T17:58:29+00:00"
},
{
"name": "masterminds/html5",
"version": "2.7.6",

View File

@ -13,4 +13,5 @@ return [
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];

View File

@ -0,0 +1,17 @@
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
// $product = new Product();
// $manager->persist($product);
$manager->flush();
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\DataFixtures;
use App\Entity\Atelier;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AtelierFixture extends Fixture
{
public function load(ObjectManager $manager): void
{
$faker = \Faker\Factory::create("fr_FR");
for($i=0; $i<= 20; $i++){
$atelier = new Atelier();
$atelier->setNom($faker->word)->setDescription("# " . $faker->sentence(3) . "\n" . $faker->paragraph());
$manager->persist($atelier);
}
$manager->flush();
}
}

View File

@ -22,6 +22,18 @@
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-fixtures-bundle": {
"version": "3.4",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
},
"files": [
"src/DataFixtures/AppFixtures.php"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.2",
"recipe": {