Skip to content

make:security:form-login : test contains "setEmail" - whatever the getUserIdentifier uses #1713

@Yopai

Description

@Yopai

make:security:form-login, when asked to generate unit tests, generate the following line :

        $user = (new User())->setEmail('[email protected]');

It works if the user entity has been generated with the default identifier property ("email"). But if you use another property when using make:form-login (in my case : username), it won't be consistent. And either generates an error, because there is no "email" property. Or, if you added one, makes the test fail, or generates an error, as we try to create a user with an email but without username...

I suggest one (or more) the following :

  • add a comment above this line, saying "Please adjust the following line if your User Entity use another identifier property than Email"
  • outputs the same as a warning on the command line
  • try to detect which property is used as userIdentifier
    • use Reflection to get the body of getUserIdentifier
    • use Reflection to fill in every property of an User object with random, different, values, and check which one is returned by getUserIdentifier
  • ask on the command line the name of the property used as userIdentifier
  • require developer to write a "setUserIdentifier" method in his User class, or allow it and detect its presence with method_exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions