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

Transaction mode default behaviour for Yii2 #4417

Closed
StalkAlex opened this issue Jul 24, 2017 · 5 comments
Closed

Transaction mode default behaviour for Yii2 #4417

StalkAlex opened this issue Jul 24, 2017 · 5 comments

Comments

@StalkAlex
Copy link

StalkAlex commented Jul 24, 2017

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.

  • Codeception version: 2.3.4
  • PHP Version: 7.1.3
  • Operating System: Centos 7
  • Installation type: Composer
@samdark
Copy link
Collaborator

samdark commented Jul 25, 2017

What's the database used?

@samdark
Copy link
Collaborator

samdark commented Jul 25, 2017

What's Yii 2 version?

@samdark
Copy link
Collaborator

samdark commented Jul 25, 2017

@DavertMik what's intended behavior for the case described?

@samdark samdark added the Yii label Jul 25, 2017
@StalkAlex
Copy link
Author

@samdark 2.0.12 and Postgres for database.

@jorgdec
Copy link
Contributor

jorgdec commented Aug 18, 2017

@samdark We have the same issue.

It can be fixed by setting the transaction to true in the unit.suite.yml file. Normally, this value is true by default, since it is copied from the cleanup value that is true by default.

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
Database is mysql 5.6

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

No branches or pull requests

3 participants