Skip to content

Commit f440659

Browse files
#5 composer require --dev orm-fixtures. Add Admin user fixture. Add make doctrine/fixtures task on make start
1 parent b685499 commit f440659

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SHELL := /bin/bash
44
DOCKER_RUN_PHP = docker compose -f .docker/compose.yaml run --rm php "bash" "-c"
55
DOCKER_COMPOSE = docker compose -f .docker/compose.yaml
66

7-
start: upd doctrine/migrations assets/install #[Global] Start application
7+
start: upd doctrine/migrations doctrine/fixtures assets/install #[Global] Start application
88

99
src/vendor: #[Composer] install dependencies
1010
$(DOCKER_RUN_PHP) "composer install --no-interaction"
@@ -38,7 +38,10 @@ logs: #[Docker] Show logs
3838
$(DOCKER_COMPOSE) logs -f
3939

4040
doctrine/migrations: #[Symfony] Run database migration
41-
$(DOCKER_RUN_PHP) "bin/console do:mi:mi --no-interaction"
41+
$(DOCKER_RUN_PHP) "bin/console doctrine:migrations:migrate --no-interaction"
42+
43+
doctrine/fixtures: #[Symfony] Run database fixtures load
44+
$(DOCKER_RUN_PHP) "bin/console doctrine:fixtures:load --no-interaction"
4245

4346
assets/install: #[Symfony] Install assets
4447
$(DOCKER_RUN_PHP) "bin/console assets:install"

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"symfony/flex": "^v2.3"
1515
},
1616
"require-dev": {
17+
"doctrine/doctrine-fixtures-bundle": "^3.6",
1718
"friendsofphp/php-cs-fixer": "*",
1819
"phpstan/extension-installer": "*",
1920
"phpstan/phpstan": "*",

config/bundles.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
1515
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
1616
CleverAge\DoctrineProcessBundle\CleverAgeDoctrineProcessBundle::class => ['all' => true],
17+
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
1718
];

src/DataFixtures/AppFixtures.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the CleverAge/ProcessBundleDemo package.
5+
*
6+
* Copyright (c) Clever-Age
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace App\DataFixtures;
13+
14+
use CleverAge\UiProcessBundle\Entity\User;
15+
use Doctrine\Bundle\FixturesBundle\Fixture;
16+
use Doctrine\Persistence\ObjectManager;
17+
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
18+
19+
class AppFixtures extends Fixture
20+
{
21+
public function __construct(private readonly UserPasswordHasherInterface $passwordEncoder)
22+
{
23+
}
24+
25+
public function load(ObjectManager $manager): void
26+
{
27+
$admin = new User();
28+
$admin->setEmail('[email protected]');
29+
$admin->setRoles(['ROLE_USER', 'ROLE_ADMIN']);
30+
$admin->setPassword($this->passwordEncoder->hashPassword($admin, '[email protected]'));
31+
32+
$manager->persist($admin);
33+
34+
$manager->flush();
35+
}
36+
}

symfony.lock

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
"src/Repository/.gitignore"
2323
]
2424
},
25+
"doctrine/doctrine-fixtures-bundle": {
26+
"version": "3.6",
27+
"recipe": {
28+
"repo": "github.com/symfony/recipes",
29+
"branch": "main",
30+
"version": "3.0",
31+
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
32+
},
33+
"files": [
34+
"src/DataFixtures/AppFixtures.php"
35+
]
36+
},
2537
"doctrine/doctrine-migrations-bundle": {
2638
"version": "3.2",
2739
"recipe": {

0 commit comments

Comments
 (0)