Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#11 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
38/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
php
领域
testing

调研方向

从 src/Codeception/Module/Doctrine2.php 中链接的 haveInRepository 实现开始,位置大约在第 504-530 行,并将其与 grabEntityFromRepository 进行比较。在决定契约之前,检查现有的返回值行为和相关用法;完成意味着该提案已通过经过测试并记录在案的 haveInRepository 返回值得到解决。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
PHP
星标
4
派生
2
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Codeception/module-doctrine 的其他 Issue

查看 Codeception/module-doctrine 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。