-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Transaction mode default behaviour for Yii2 #4417
Comments
What's the database used? |
What's Yii 2 version? |
@DavertMik what's intended behavior for the case described? |
@samdark 2.0.12 and Postgres for database. |
@samdark We have the same issue. It can be fixed by setting the In the initialise function of the Yii2 module, you see this code: public function _initialize()
{
if ($this->config['transaction'] === null) {
$this->config['transaction'] = $this->config['cleanup'];
}
if (!is_file(Configuration::projectDir() . $this->config['configFile'])) {
throw new ModuleConfigException(
__CLASS__,
"The application config file does not exist: " . Configuration::projectDir() . $this->config['configFile']
);
}
$this->defineConstants();
} If you don't set the transaction, it will be copied from cleanup (that is true by default), but only the first time the module is initialized. When the first method of the test is finished, the config is restored to the backupConfig var. This happens in Subscriber/Module.php in the after function. Since the code above only changes the config, and not the backupConfig, after the reset, the transaction isn't set anymore to true. The fix would be to change the _initialize function to also modify the backupConfig like this: public function _initialize()
{
if ($this->config['transaction'] === null) {
$this->config['transaction'] = $this->backupConfig['transaction'] = $this->config['cleanup'];
} Yii2 version is 2.0.12 |
What are you trying to achieve?
Run all functional tests in transaction. I haven't specified transaction or cleanup params in config. As I understand they're both true by default.
What do you get instead?
Instead I get only first test run in transaction. All next tests are running not in transaction. And after whole run I have some useless rows in db that cause errors on the next run. Transactions are suppose to solve such problems.
Details
I did some research.
This method works once at the beginning and sets transaction to true, then transaction starts in before and rollback in after methods respectively, but on the next test this method is not working(due to its purpose ofc) and transaction wil not start here and will not rollback here as transaction option get null value not true like in initialize method. Is this desirable behaviour or a bug? I waste quite a big time to figure it out. It's better be fixed or documented.
The text was updated successfully, but these errors were encountered: