Codeception / Codeception/module-doctrine

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

オープン
#11 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
4
フォーク
2
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start with src/Codeception/Module/Doctrine2.php at the linked haveInRepository implementation around lines 504-530, and compare it with grabEntityFromRepository. Review the existing return-value behavior and related usage before deciding the contract; done means the proposal is resolved with a tested, documented return value for haveInRepository.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
testing
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。