-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Behat, foundry and manager registry of the app on different database connection instances #234
Comments
I believe foundry is being booted by the bundle earlier (with a different kernel). For testing, foundry is optimized for PHPUnit. This trait for your @wouterj, do you use foundry with behat? If so, do you have any insights? |
@kbond well that makes a lot of sense, though I don't get the part how bundle is getting registered with another kernel different from what is in behat contexts. Anyway, did some testing and seems the issue is resolved by manually booting foundry... So what I did, I've turned off the bundle and added extra method in the FeatureContext class: <?php
...
class FeatureContext implements Context
{
...
/**
* @BeforeScenario
*/
public function bootFoundry()
{
if (Factory::isBooted()) {
return;
}
$configuration = new Configuration();
try {
$configuration->setManagerRegistry($this->managerRegistry);
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException('Could not boot Foundry, is the DoctrineBundle installed/configured?', 0, $e);
}
TestState::bootFoundry($configuration);
} And it works! |
Glad to hear! You may want to add an "after scenario" hook to shutdown foundry. BTW, you can use foundry's I'm thinking we should include this context within foundry itself. This would remove the need for you to use
What gives the nice DX of foundry is a lot of static state. This does create a lot of complexity and weird edge cases. Do you have some "before suite" hooks that boots the kernel then shuts it down? This would cause foundry to be booted with a different kernel instance. |
Well it comes with a price... All the magic of using factories/stories as services and ect. from the extension is unavailable this way, so it is not 100% fix for the situation. Trying to figure out the working configuration rn. Regards BeforeSuite or any other extra kernel boots - no, I've just introduced behat to this project and it's configuration is in a very early stage. |
That's true. What happens when you just force boot foundry in your before scenario hook? This is what I do in the PHPUnit trait I linked above. Something like: use Zenstruck\Foundry\Test\TestState;
class FeatureContext implements Context
{
...
/**
* @BeforeScenario
*/
public function bootFoundry()
{
TestState::bootFromContainer($this->container); // inject the container into this context
}
/**
* @AfterScenario
*/
public function shutdownFoundry()
{
TestState::shutdownFoundry();
}
} |
That works! Unfortunately it seems behat mink is booting another kernel for resolving endpoints in Contexts which gets another connection instance and then nothing in my Context's transaction is available for endpoint. It seems the whole concept might be not very possible in behat anyways :( |
You are using the |
For the transactions, are you using |
That is brilliant! I did have Thanks a lot! |
Not sure what to do next with the issue though. I think using behat with DB transactions is quite an edge case as the ORM Purger is the common approach. Adding hook context would be helpful, but it would make sense only in use together |
The |
Hi! Yes, we are using Behat + FriendsOfBehat SymfonyExtension + Foundry in our tests. We are indeed using It would be cool to write a Behat extension that does this correctly. I believe we still have some weird edge cases (not sure if it's due to Foundry or something else). I personally have the feeling it would be better to not register the FoundryBundle when you're using Behat, and instead set-up Foundry using a BehatExtension. |
I'm not sure why or how this happens, but it seems that foundry somehow gets different connection instance. I found this while trying to make foundry work with my behat setup, which I'm trying to make to work in database transaction mode, as in my case wiping data from database is not the option (for system to work some huge data package needs to be in the database and importing 0.5gb data on every scenario would make execution time too long).
Some simplified examples how to reproduce:
Or:
The suggested lib to have database resets -
dama/doctrine-test-bundle
would fail in the same fashion and using it would just result in data written into database.Unfortunately I'm not sure why this happens so can't make MR with solution proposed.
Some additional info:
The text was updated successfully, but these errors were encountered: