Codeception / Codeception/module-doctrine

Second and next requests in tests reloads entities from doctrine entity manager

未关闭
#18 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PHP
星标
4
派生
2
PR 合并指标
30 天内没有已合并 PR

描述

#### What are you trying to achieve?

All requests should use same instances of entities during the test.

#### What do you get instead?

Second and subsequent requests reloads entities which causes instances within test to be different from those that are used within those requests.

```php
grabEntityFromRepository(Foo::class, ['id' => 1]); // spl_object_hash: 000000006cf7be51000000007baa4f48
$tester->sendPUT('/foo'); // spl_object_hash: 000000006cf7be51000000007baa4f48 same as first
$tester->sendPUT('/foo'); // spl_object_hash: 000000006cf7b6b0000000007baa4f48 different than previous
$tester->sendPUT('/foo'); // spl_object_hash: 000000006cf7b5c0000000007baa4f48 different than previous

// $instance here has different values than those used within second and any subsequent request
}
```

### Workaround
In order to get latest version of the entity we have to "re-grab" it from repository:
```php
grabEntityFromRepository(Foo::class, ['id' => 1]); // spl_object_hash: 000000006cf7b5c0000000007baa4f48 is same as in last request
```
But it would be better to reuse the first instance the same way first request does.

### Details

* Codeception version: 2.5.1
* PHP Version: 7.1.24
* Operating System: Linux
* Installation type: Composer
* Suite configuration:

```yml
modules:
enabled:
- Asserts: ~
- Symfony:
cache_router: true
rebootable_client: true
- REST:
url: /api
depends: Symfony
- Doctrine2:
depends: Symfony
- \Helper\Api: ~
disabled:
- PhpBrowser
- WebDriver
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 Doctrine2 模块及其 Symfony 依赖项开始,使用提供的测试流程并启用 rebootable_client,以复现跨请求的实体标识变化。跟踪 entity manager 和请求的生命周期,然后验证最初获取的实体实例在第二次及后续请求中会被复用,同时不会破坏文档中说明的重新获取 workaround。

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

评估

技术栈
php
领域
databases, testing-qa
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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