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

Stuck between DAMA and FOUNDRY/RESTDATABASE #251

Open
DigitalTimK opened this issue Feb 5, 2022 · 5 comments
Open

Stuck between DAMA and FOUNDRY/RESTDATABASE #251

DigitalTimK opened this issue Feb 5, 2022 · 5 comments

Comments

@DigitalTimK
Copy link

DigitalTimK commented Feb 5, 2022

Good Morning!

Epilogue

To be honest, maybe I am doing something totally wrong, since my issue is a common use-case, but it seems that I am the only one having this issue.

Environment

  • Symfony 5.4
  • PHPunit is using DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension-extension
  • Functional tests are using trait Zenstruck\Foundry\Test\ResetDatabase
  • MariaDB

Use Case

  • Functional test (PantherTestCase) of a simple contact form (name, email-address, message) on a website
  • The controller treats the submitted form and is checking if email-address is already known to allocate the message to that existing person-object
  • So this is why the functional test creates a person-object ($person = PersonFactory::createOne(['email' => 'john@doe.com']);) before the form is filled and submitted.

Problem 1

Once the form is submitted by the test it gets treated by the controller, but the Person-object is not existing anymore (the entire database is empty). The database seems be rolled back by DAMA.

Solution 1

According to the proposal here, I added this to the above mentioned function test-class.

    public static function setUpBeforeClass(): void
    {
        parent::setUpBeforeClass();
        StaticDriver::setKeepStaticConnections(false);
    }

    public static function tearDownAfterClass(): void
    {
        StaticDriver::setKeepStaticConnections(true);
        parent::tearDownAfterClass();
    }

Problem 2

Solution 1 is working perfectly. But only if that test is executed in isolation. Once the full test-set is launched it explodes for subsequent tests with:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'something' for key 'PRIMARY'

So it seems that RESTDATABASE is not executed anymore from that test-class and on ...

Solution 2

--> I have no idea how to solve this. Any idea?
Or is this a bug?

Many thanks for sharing your thoughts!

Cheers
Tim!

@kbond
Copy link
Member

kbond commented Feb 8, 2022

Hey @DigitalTimK,

I believe I understand the problem but I don't know there is a great solution. The logic to "change how reset database" resets the database when Dama is enabled assumes you are running it for your entire suite.

To clarify, does your test suite run successfully if Dama is disabled?

For you app, what about grouping the panther tests together and running them as a separate run with Dama disabled? It would require a second phpunit.xml which is unfortunate.

For a proper solution, I think we may have to wait until PHPUnit 10's event system as suggested here, and for DAMA to utilize these events.

@DigitalTimK
Copy link
Author

Hello @kbond,

thanks for your response. I am not the best friend of the second phpunit.xml workaround. But as it isn't that urgent currently I will hope and wait for PHPUnit 10 ;-)

But what makes me really wonder is that I am the first coming up with the issue. Nobody doing functional testing?

@kbond
Copy link
Member

kbond commented Feb 27, 2022

But what makes me really wonder is that I am the first coming up with the issue. Nobody doing functional testing?

To clarify, this is a problem if using Foundry, DAMA, and Panther together. I suspect it must be rare to use all three in the same suite? My functional tests use Foundry, DAMA and the standard kernel browser (no panther).

@Cafeine42
Copy link

Hello @kbond ,

I'm having this problem too, I need Panther to test an app that uses Symfony UX, so lots of javascript.

Is there an approach you recommend to take advantage of fixtures with Panther?

@kbond
Copy link
Member

kbond commented Oct 18, 2022

Hi @Cafeine42, at this point, you'll need to create a second panther-specific phpunit.xml that doesn't have DAMA enabled.

phpunit.xml: integration/unit tests with DAMA enabled
phpunit-panther.xml: e2e/panther tests with DAMA disabled

You'll have to run two test suites:

phpunit -c phpunit.xml # unit/integration tests
phpunit -c phpunit-panther.xml #e2e/panther tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants