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!
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()?
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.
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.