Codeception fixtures loading twice


(Baggerone) #1

We have old codeception api tests that succeed on yii 2.0.11.2. However on yii 2.0.12, they get an error when loading fixtures (integrityError due to primary key already existing).

Debugging it, I found the code that triggers the error (framework/db/Command.php line 842). If I check the contents of the db table before that line is executed, I see that the db table is already populated with the fixture.

So, it appears that yii tries to load the fixtures in different places and ends up trying to reload the same ones on top of each other.

This is on php7.

application/tests/api/fixtures/UserFixture.php




<?php

namespace tests\api\fixtures;


use yii\test\ActiveFixture;


class UserFixture extends ActiveFixture

{

    public $modelClass = 'common\models\User';

    public $dataFile = 'tests/api/fixtures/data/User.php';

    public $depends = [

    ];

}



application/tests/api/BaseCest.php




<?php


use tests\api\FixtureHelper;




class BaseCest

{

    /** @var  tests\api\FixtureHelper */

    public $fixtureHelper;


    public function _inject(tests\api\FixtureHelper $fixtureHelper)

    {

        $this->fixtureHelper = $fixtureHelper;

    }


    public function _before(ApiTester $I)

    {

        $this->fixtureHelper->_beforeSuite();

    }


    public function _after(ApiTester $I)

    {

        $this->fixtureHelper->_afterSuite();

    }

}




(Jacob Moen) #2

[color="#006400"]/* moved to Testing */[/color]


(Alirz23) #3

I am not sure what exactly you are doing, by reading your post I can tell you are providing yii with primary keys as part of your fixtures, I would say let the database generate the keys for you, even if your fixtures are duplicated you won’t run into this problem.


(Baggerone) #4

Thank you for the reply.

I tried it without the primary key included. Unfortunately, one of the other fields was a unique field and so the same error popped up on that one.

I wonder if yii and codeception are both loading fixtures separately somehow.


(Niyaz Musin) #5

Could you solve this problem?