Codeception / Codeception/module-doctrine

Memory Overflow at Doctrine Module with related entities

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

描述

If an entity is on the `1` side of a `1:n` relationship (i.e. it has `oneToMany`), and I handle it with the Doctrine Module, the object gets infinitely large, thereby causing a PHP memory overflow.

### Details

I've set up these two entities:
```yml
AppBundle\Entity\TestGroup:
type: entity
table: test_group

id:
id:
type: integer
generator:
strategy: IDENTITY

fields:
name:
type: string
length: 50
nullable: true

oneToMany:
test_user:
targetEntity: TestUser
mappedBy: test_group
```

```yml
AppBundle\Entity\TestUser:
type: entity
table: test_user

id:
id:
type: integer
generator:
strategy: IDENTITY

fields:
group_id:
type: integer
nullable: true
name:
type: string
length: 50
nullable: true

manyToOne:
test_group:
targetEntity:
inversedBy: test_user
joinColumn:
name: group_id
referencedColumnName: id
```
Now I run this functional test:
```php
public function tryMemoryLeak (FunctionalTester $I)
{
$group = new \AppBundle\Entity\TestGroup();
var_dump($group);
$I->persistEntity($group);
die;
var_dump($group);
}
```
Result: The output from `var_dump` is normal; and the entity exists in the database. But as soon as I remove `die;` the bug occurs: I get endless (i.e. hundreds or thousands of lines) output in the console. The same happens if I fetch the entity from the database with `$I->grabEntityFromRepository`.
This explains what I initially observed: If I try to pass the object to some function, I get a memory overflow crash from PHP.

I've tried it with SQLite and PostgreSQL.

If I do the same with the `TestUser` entity, everything is normal. So I'm figuring it has something to do with the `oneToMany` setting.

And if I do it in a controller, everything is fine too - so I'm figuring there's no error in the entities.

### Setup

* Codeception version: 2.3.5
* PHP Version: 7.1
* Operating System: Windows 10

贡献指南

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

调研方向

先从使用 persistEntity 和 grabEntityFromRepository 的功能测试开始,然后检查 Doctrine 模块如何处理具有 oneToMany 关系的实体。将 TestGroup 和 TestUser 的情况与控制器的行为进行比较;完成标准是相关实体不再产生递归输出或内存溢出。

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

评估

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

把新 issue 发到你的邮箱

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