Closed
Description
Related to: #366
Almost all our functional tests has been broken by #366 ! :(
Our project has very complex user-account-roles-subscriptions relations an hierarchy. And very complex bussiness objects inheritance and relations. It is a real pain to emulate realistic test environment... So, the decision for us:
- Create maximum of dictionaries, users and user data at once, before all tests.
- Instance one connection in setUp() and set it in custom Client and start transaction
- It allows to test some multipage workflows, check data directly from server-side before/after any request and rollback all modifications in tearDown(). Fast and clear.
See http://alexandre-salome.fr/blog/Symfony2-Isolation-Of-Tests for details
This recipe doesn`t work after #366.
Can you make this good functional configurable?
Activity
hmillet commentedon Mar 26, 2015
Got exactly the same trouble.
Using the same trick of Alexandre Salome to isolate my PHPUnit - FrameworkBundle\Client tests.
How to get a good new way to isolate our tests ?
Maybe have a way to tell the connection that if it close, it should rollback the transaction, and not commit it
dvc commentedon Mar 26, 2015
May be workaround to avoid new code:
hmillet commentedon Jul 31, 2015
This workaround works for me, thanks a lot @dvc
mtibben commentedon Sep 2, 2015
I have the same problem. We run each test inside a transaction, which is rolled back on teardown. This keeps the test db in a clean state without the need to rebuild it for each test.
When using symfony's test client to simulate http requests, after each request the kernel is shutdown which now means all connections are closed.
It would be nice if there was a way to avoid that.
craue commentedon Feb 25, 2016
I'm stuck on DoctrineBundle 1.3 because of this issue. It breaks a lot of my tests where assertions on entities are made after a request.
mtibben commentedon Feb 25, 2016
I worked around the issue by decorating the connection in tests and noop
the close function
On Thu, 25 Feb 2016, 9:28 PM Christian Raue notifications@github.com
wrote:
craue commentedon Feb 25, 2016
@mtibben, currently I'm calling
close
manually intearDown
, so noop-ing it is not an option. I tried @dvc'sshutdown
code and it would solve the issue, but I'd prefer a proper fix/feature instead of such a workaround.mtibben commentedon Feb 25, 2016
Yeah to get around that I created a
rollbackTestTransactionAndClose
function - here's the codedmaicher commentedon Apr 9, 2019
The issue is quite old but I think this bundle will simplify all your transactional test logic quite a bit 😉
https://github.com/dmaicher/doctrine-test-bundle
alcaeus commentedon Apr 12, 2019
Closing as per #638 (comment).