Codeception / Codeception/module-doctrine

Proposal: haveInRepository returns the created entity instead of the primary key

Ouverte
#11 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
PHP
Étoiles
4
Forks
2
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

In many tests i have come across situations like this:
```php
$I->haveInRepository(User::class, [
'name' => 'Jane',
'email' => 'jane_doe@gmail.com',
'password' => '123456',
'enabled' => true
]);
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'jane_doe@gmail.com'
]);
// do assertions with the $user
```
Use `haveInRepository`, and then be forced to use `grabEntityFromRepository` to get the entity i just persisted. If i want to check that an entity listener is working, for example, i always have to execute those two statements.

My point is that this would be more useful:
```php
$user = $I->haveInRepository(User::class, [
'name' => 'Jane',
'email' => 'jane_doe@gmail.com',
'password' => '123456',
'enabled' => true
]);
// do assertions with the $user
```
if i wanted to know the primary key of that entity, i would simply write:
```php
$user->getId();
```
In this context, the ORM is useful for its ability to abstract the details of the persistence process and leave it to me as a programmer to worry more about the data i am working with.

I'm not saying that getting the primary key is not useful, i am saying that it is much more useful to get the entity, where there is more information to work with in my tests, including the persistence identifier.

https://github.com/Codeception/module-doctrine2/blob/1ae32bdcd77abde4a583462f5949fc86b9bda2a2/src/Codeception/Module/Doctrine2.php#L504-L530

Please let me know your opinions about it.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par src/Codeception/Module/Doctrine2.php, au niveau de l’implémentation liée de haveInRepository autour des lignes 504-530, et comparez-la avec grabEntityFromRepository. Examinez le comportement existant de la valeur de retour et les utilisations associées avant de décider du contrat ; c’est terminé lorsque la proposition est résolue avec une valeur de retour testée et documentée pour haveInRepository.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
php
Domaine
testing
Type d'issue
Fonctionnalité
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.