fixtures do not unload and globalfixture yields integrity exception

here is the code straight from advance template unit test





<?php


namespace tests\codeception\frontend\unit\models;


use tests\codeception\frontend\unit\DbTestCase;

use tests\codeception\common\fixtures\UserFixture;

use Codeception\Specify;

use frontend\models\SignupForm;


class SignupFormTest extends DbTestCase

{


    use Specify;


    public function testCorrectSignup()

    {

        $model = new SignupForm([

            'username' => 'some_username',

            'email' => 'some_email@example.com',

            'password' => 'some_password',

        ]);


        $user = $model->signup();


        $this->assertInstanceOf('common\models\User', $user, 'user should be valid');


        expect('username should be correct', $user->username)->equals('some_username');

        expect('email should be correct', $user->email)->equals('some_email@example.com');

        expect('password should be correct', $user->validatePassword('some_password'))->true();

    }


    public function testNotCorrectSignup()

    {

        $model = new SignupForm([

            'username' => 'troy.becker',

            'email' => 'nicolas.dianna@hotmail.com',

            'password' => 'some_password',

        ]);


        expect('username and email are in use, user should not be created', $model->signup())->null();

    }


    public function fixtures()

    {

        return [

            'user' => [

                'class' => UserFixture::className(),

                'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',

            ],

        ];

    }

}




Issue #1: the test runs ok, but the loaded data from fixture [@tests/codeception/frontend/unit/fixtures/data/models/user.php] was not unloaded/removed after the test. I verify this by checking the table data. I think it should but it doesnt.

Issue #2: I try to be a smart ass and use globalFixtures because it disables the database integrity check before loading other DB fixtures, and re-enable it after other DB fixtures are unloaded [http://www.yiiframework.com/doc-2.0/guide-test-fixtures.html#defining-and-using-global-fixtures]

I add the below code and comment out the fixture()




    public function globalFixtures() {

       return [

           'user' => [

               'class' => UserFixture::className(),

               'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',

           ],

       ];

    }


    // public function fixtures()

    // {

    //     return [

    //         'user' => [

    //             'class' => UserFixture::className(),

    //             'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',

    //         ],

    //     ];

    // }



Well, I got DB exception Integrity constraint violations. This is weird because globalFixtures suppose to disable the integrity check ???

[color="#006400"]/* Moved from "General" to "Testing" */[/color]

What´s your db setup in unit.suite.yml / acceptance.suite.yml?

Is Cleanup true?


        

Db:

            # see http://codeception.com/docs/09-Data

            dsn: ...

            user: ...

            password: ...

            dump: 'tests/codeception/_data/dump.sql'

            populate: true     # load dump.sql ?

            cleanup: true      # true= cleanup db after each test

Maybe a workaround will help:

Try to reset your db via tests/codeception/_data/dump.sql:

DELETE FROM user;