Codeception / module-doctrine

Next gen Doctrine module for Codeception
MIT License
2 stars 1 forks source link

Is the entity manager not released from memory after each unit test? #10

Open ThomasLandauer opened 3 years ago

ThomasLandauer commented 3 years ago

When running my entire unit test suite, I'm getting one of these two errors

In UnaryOperator.php line 17:
Error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 140142348222464 bytes)

In UnaryOperator.php line 84:
Compile Error: Declaration of PHPUnit\Framework\Constraint\UnaryOperator::failureDescription($other): string must be compatible with PHPUnit\Framework\Constraint\Constraint::failureDescription($joinAssociationDeclaration):

... always on the same tests. The only thing they have in common is that they fetch stuff from the database.

But when I run the affected test files alone, everything's fine.

This makes me suspect that something with memory management is wrong. Is the entity manager being kept in memory between test runs?

Naktibalda commented 3 years ago

That error doesn't look like memory leak, PHP tries to allocate 140 terabytes in one go.

ThomasLandauer commented 3 years ago

140 TB? Well, maybe I should go and buy more RAM then... ;-)

I now moved the first of the affected tests to functional suite, and the entire suite runs smoothly there. How can that be?? What's the difference between unit and functional runner?

It probably has something to do with a change I made in the app in an entity: Some setter is now doing a change in a related entity, something like:

function setOk(bool $ok)
{
    $this->ok = $ok;
    $this->getFoo()->setOk($ok); // <= `Foo` = related entity
}

Cause when I remove this line again, unit suite works too (i.e. fails, but doesn't crash).