Skip to content

make:user and make:entity workflow not working properly with Symfony 6.2 #1279

Open
@fabpico

Description

@fabpico

I want to use make:user as in https://symfony.com/doc/current/security.html#the-user.

I have PHP 8.1.11. My composer.json:

{
  "require": {
    "symfony/runtime": "^6.2",
    "symfony/http-kernel": "^6.2",
    "symfony/framework-bundle": "^6.2",
    "symfony/console": "^6.2",
    "doctrine/doctrine-bundle": "^2.8"
  },
  "require-dev": {
    "phpunit/phpunit": "^9.5",
    "symfony/maker-bundle": "^1.48",
    "symfony/security-bundle": "^6.2"
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  },
  "config": {
    "allow-plugins": {
      "symfony/runtime": true
    }
  }
}

When I make

php bin/console make:user

I receive

[ERROR] Missing package: Doctrine must be installed to store user data in the database, run:                           
                                                                                                                        
         composer require orm

I assume this is a Flex alias. Because when I do:

composer require orm

I receive

Did you mean one of these?   
      doctrine/orm             
      nelmio/alice             
      propel/propel            
      symfony/orm-pack         
      topthink/think

I propose to directly suggest the needed package, to be friendly with non-Flex users. So when I do (after removing composer.lock):

composer require symfony/orm-pack

I can use make:user until this happens

Doctrine ORM Manager named "" does not exist.

So I go the other way around and configure the ORM first https://symfony.com/doc/current/doctrine.html . It says I have to install:

symfony/orm-pack
symfony/maker-bundle

Already done.

DBAL connection works, tested with temporary call in controller:

$result = $this->connection->executeQuery('SELECT * FROM "public"."foo"');
$foo = $result->fetchAssociative();

Now I try out make:entity (just to test ORM)

https://symfony.com/doc/current/doctrine.html#creating-an-entity-class

Still I get

Doctrine ORM Manager named "" does not exist.

I suggest that a minimum ORM configuration is described in this make:entity documentation, or a least a direct link to another documentation page to quickly configure ORM.
As in https://stackoverflow.com/questions/35810105/doctrine-orm-manager-named-does-not-exist I tried

  orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    auto_mapping: true

I run make:entity again, I receive

created: src/Entity/User.php
created: src/Repository/UserRepository.php
                                                                                                                        
 [ERROR] Only attribute mapping is supported by make:entity, but the <info>App\Entity\User</info> class uses a different
         format. If you would like this command to generate the properties & getter/setter methods, add your mapping    
         configuration, and then re-run this command with the <info>--regenerate</info> flag.

https://stackoverflow.com/a/73145112/4840661 /which relates to #1152 and #841), suggest to downgrade to symfony/maker-bundle:1.43 .

I try again with v1.43, I receive a similar message

created: src/Entity/User.php
created: src/Repository/UserRepository.php

                                                                                                                        
 [ERROR] Only annotation or attribute mapping is supported by make:entity, but the <info>App\Entity\User</info> class uses
         a different format. If you would like this command to generate the properties & getter/setter methods, add your
         mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.

Back to make:user, assuming that at least the ORM is configured correctly, I receive (among other things)

Success!

The way until this success message was very laborious, it should be more easy and straightforward.

Summarized

  • A missing dependency should not be complained with a Flex alias, but with the correct package name
  • make:user and make:entity should handle unconfigured ORM, maybe create a valid default config
  • make:entity should not throw that “Only attribute”/”Only annotation” error

Other people also still complain about the annotation error message, even after closing the issue #841 (comment) .

Metadata

Metadata

Assignees

Labels

BugBug Fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions