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

Trait or annotation to disable DAMA in some files #182

Open
bastien70 opened this issue Nov 5, 2021 · 11 comments
Open

Trait or annotation to disable DAMA in some files #182

bastien70 opened this issue Nov 5, 2021 · 11 comments

Comments

@bastien70
Copy link

bastien70 commented Nov 5, 2021

Hello, I am using DAMA for my tests.

This is useful for some tests, but not for End to End tests, since it does not support it.

But it gives me bugs because DAMA still manages to rollback certain transactions in the middle of my EndToEnd tests (those requiring that I initialize a record in the database. DAMA rollback directly)

It would be nice to have a trait or something that allows us to say in some files to disable DAMA support.

It forces me to create all the entities I need upstream, that's not cool

I found the previous issue : #171 but it doesn't seem to suit what i want

@bastien70 bastien70 changed the title Trait to disable DAMA in some files Trait or annotation to disable DAMA in some files Nov 5, 2021
@dmaicher
Copy link
Owner

dmaicher commented Nov 8, 2021

Feel free to look into it 👍

A workaround might be something like this (not tested):

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use PHPUnit\Framework\TestCase;

class MyTestWithoutDAMATransactionManagement extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        StaticDriver::setKeepStaticConnections(false);
    }

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

    // your tests
}

@bastien70
Copy link
Author

It seems to work ! Thank you very much !

@dmaicher
Copy link
Owner

I also recently had a use-case for this on one of my apps. I looked into it a bit and with the current PHPUnit Extensions this seems rather complicated to achieve as we don't have access to much in the Hooks.

I would wait for the new PHPUnit 10 event system to achieve this.

@bastien70
Copy link
Author

I also recently had a use-case for this on one of my apps. I looked into it a bit and with the current PHPUnit Extensions this seems rather complicated to achieve as we don't have access to much in the Hooks.

I would wait for the new PHPUnit 10 event system to achieve this.

Awesome ! I can not wait to see it. I was a bit disturbed because with your fallback method we get a warning on each of the tests, because the AbstractStaticDriver is supposed to be internal

@DigitalTimK
Copy link

DigitalTimK commented Feb 4, 2022

That's a feature that would be also useful for me!!!!

But don't forget here to call parent::setUpBeforeClass()and parent::tearDownAfterClass() too.


Update

Solution works only in isolation of that class. Test-classes executed after MyTestWithoutDAMATransactionManagement-class fail, because the database is not reset anymore (Zenstruck\Foundry\Test\ResetDatabase). Unfortunately I have no idea how to solve this ...

@chriskaya
Copy link

chriskaya commented Feb 21, 2022

My PR having been rejected by @dmaicher for reasons I totally understand, I'm now using a custom phpunit extension built on top of doctrine-test-bundle.

If you need this, you may do the same: https://github.com/chriskaya/custom-dama-extension/blob/main/CustomDamaExtension.php

BTW, thx @dmaicher for your work :)

@MalikOvaiz

This comment was marked as off-topic.

@kAlvaro

This comment was marked as resolved.

@dmaicher

This comment was marked as resolved.

@kAlvaro

This comment was marked as resolved.

@osteel
Copy link

osteel commented Jan 18, 2024

A workaround might be something like this (not tested):

Just stumbled upon this by googling around – this should be mentioned in the doc IMO :)

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

No branches or pull requests

7 participants