Yii2 codeception - [PDOException] There is already an active transaction

Hello guys!

I have this functional test:

public function testSomething(FunctionalTester $I)
    {
        $I->amOnRoute('fiscalizacao/acompanhamento/interagir', ['id' => 1]);

        $I->submitForm('body form', [
            'Interacao[comentario]' => 'Comentário Teste',
        ]);
        ...
    }

// In the controller
\Yii::$app->db_foo->beginTransaction(); // the problem happens here

When I run the test, it results in “[PDOException] There is already an active transaction” because, when the form is sent, I begin a transaction in the controller to avoid partial data saving. But it is conflicting with the transaction begun by fixtures!

Is there anyway to avoid this problem?
Thank you!

Stacktrace:

#1  .../vendor/yiisoft/yii2/db/Transaction.php:128
#2  .../vendor/yiisoft/yii2/db/Connection.php:753
#3  .../sistemas/modules/fiscalizacao/controllers/AcompanhamentoController.php:132
#4  sistemas\modules\fiscalizacao\controllers\AcompanhamentoController->actionInteragir
#5  .../vendor/yiisoft/yii2/base/InlineAction.php:57
#6  .../vendor/yiisoft/yii2/base/Controller.php:157
#7  .../vendor/yiisoft/yii2/base/Module.php:528
#8  .../vendor/yiisoft/yii2/web/Application.php:103
#9  .../vendor/symfony/browser-kit/Client.php:351
#10 Codeception\Lib\InnerBrowser->submitForm

Unfortunately, I had to disable transactions in function testing to stop the conflicts between transactions started by Yii2 Copeception module’s TransactionForcer and those begun by Yii2 Connection::beginTransaction().

suite_namespace: sistemas\modules\fiscalizacao\tests\functional
actor: FunctionalTester
modules:
    enabled:
        - Filesystem
        - Yii2:
            cleanup: true
            transaction: false #<<< this line

Is there a way to disable only for a specific test (Cest)? Maybe inside before()?

@sammousa knows for sure.

Yes you can change module configuration for a specific test, that’s not yii specific.

However the yii module uses yii native transactions and thus should support nesting them. Please create a bugreport I’m the codeception github repository. Also if possible try creating a test case (PR) in github.com/codeception/yii2-tests.

Put a link to the created issue here in case someone finds this thread in the future.

Thank you @samdark and @sammousa!

This is very strange since I have another situations under test where I also use transactions and I have no problems like that. I tryed to investigate what the difference are but I still could not find. If I dont find, I will open the PR test as you said.

I just didn’t understands what you mean with “that’s not Yii specific”. Is not? How would I change the configs for the specific test? Thanks.