You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
<?phppublicfunctiontest(\Codeception\Actor$tester)
{
$instance = $tester->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$instance = $tester->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.
I have a problem due to different results between first run and following ones in version 2.2. I have found that removing var/cache/test/appTestDebugProjectContainer.php allows to run test as if it was always the first one. I guess that there may be an issue in the cache generation but haven't got time to investigate any further so far. This may be related to you problem…
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.
Workaround
In order to get latest version of the entity we have to "re-grab" it from repository:
But it would be better to reuse the first instance the same way first request does.
Details
The text was updated successfully, but these errors were encountered: