Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dukecz opened this issue Nov 22, 2018 · 3 comments

Comments

@Dukecz
Copy link
Contributor

Dukecz commented Nov 22, 2018

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

public function test(\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.

Details

  • Codeception version: 2.5.1
  • PHP Version: 7.1.24
  • Operating System: Linux
  • Installation type: Composer
  • Suite configuration:
modules:
    enabled:
        - Asserts: ~
        - Symfony:
            cache_router: true
            rebootable_client: true
        - REST:
            url: /api
            depends: Symfony
        - Doctrine2:
            depends: Symfony
        - \Helper\Api: ~
    disabled:
        - PhpBrowser
        - WebDriver
@Naktibalda
Copy link
Member

@Dukecz Have you got any idea how to fix it in Codeception?

@Dukecz
Copy link
Contributor Author

Dukecz commented Jan 3, 2019

@Dukecz Have you got any idea how to fix it in Codeception?

@Naktibalda Not really. I don't have even the slightest idea where the problem could be sadly.

@OphiuchusAtaraxia
Copy link

OphiuchusAtaraxia commented Mar 5, 2019

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…

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 5, 2021
@TavoNiievez TavoNiievez transferred this issue from Codeception/module-doctrine2 Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants