Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen
#11 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
38/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
php
Bereich
testing

Rechercherichtung

Beginne mit src/Codeception/Module/Doctrine2.php bei der verlinkten Implementierung von haveInRepository in etwa den Zeilen 504–530 und vergleiche sie mit grabEntityFromRepository. Überprüfe das bestehende Verhalten des Rückgabewerts und die zugehörige Verwendung, bevor du den Vertrag festlegst; abgeschlossen bedeutet, dass der Vorschlag mit einem getesteten und dokumentierten Rückgabewert für haveInRepository gelöst ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

In many tests i have come across situations like this:

        $I->haveInRepository(User::class, [
            'name' => 'Jane',
            'email' => '[email protected]',
            'password' => '123456',
            'enabled' => true
        ]);
        $user = $I->grabEntityFromRepository(User::class, [
            'email' => '[email protected]'
        ]);
		// 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:

        $user = $I->haveInRepository(User::class, [
            'name' => 'Jane',
            'email' => '[email protected]',
            'password' => '123456',
            'enabled' => true
        ]);
		// do assertions with the $user

if i wanted to know the primary key of that entity, i would simply write:

        $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.

Vorherrschende Sprache
PHP
Sterne
4
Forks
2
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus Codeception/module-doctrine

Alle Issues in Codeception/module-doctrine

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.