Codeception / module-yii2

Codeception module for Yii2 framework
MIT License
16 stars 36 forks source link

Transactional tests is not considering sequence in Postresql. Yii2 #38

Closed StalkAlex closed 2 years ago

StalkAlex commented 6 years ago

What are you trying to achieve?

I have two functional suites. LoginCest and RegistrationCest. First suite uses fixture that creates fake users. When first suite run, user table contains several users from fixture and one admin record. Important thing is admin was created by app init script before test run and when suite started it was already been there.

First suite runs successfully. Then in second RegistrationCest I get next error

[yii\db\IntegrityException] SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "user_pkey"
DETAIL:  Key (id)=(1) already exists.

And it's true, because admin record has id = 1. But it's bug, during registration new user should has been created with next id = 2. Problem is in the first test, it reset sequence for user table when Codeception applied fixtures and then didn't restore it back.

If I run RegistrationCest alone, it runs ok.

Details

class_name: FunctionalTester
modules:
    enabled:
      - Filesystem
      - Yii2
      - REST
      - Asserts
#      - Db
    config:
        Yii2:
            configFile: 'tests/codeception/_config/functional.php'
            transaction: true
            cleanup: false
        REST:
            depends: Yii2
StalkAlex commented 6 years ago

It turned out there is looking similar issue that was created long time ago. https://github.com/yiisoft/yii2/issues/8298