Yii Framework Forum: Codeception fixtures loading twice - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Codeception fixtures loading twice yii 2.0.12 has this issue but not yii 2.0.11.2

#1 User is offline   Bagger1 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-July 13

Posted 15 June 2017 - 08:27 AM

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();
    }
}

0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,697
  • Joined: 10-October 10
  • Location:Denmark

Posted 15 June 2017 - 11:05 AM

/* moved to Testing */
"Less noise - more signal"
0

#3 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,493
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 16 June 2017 - 04:47 AM

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.
0

#4 User is offline   Bagger1 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-July 13

Posted 16 June 2017 - 07:30 AM

View Postalrazi, on 16 June 2017 - 04:47 AM, said:

... I would say let the database generate the keys for you ...


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.
0

#5 User is offline   literatura 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-August 17

Posted 27 August 2017 - 01:20 PM

View PostBagger1, on 16 June 2017 - 07:30 AM, said:

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.

Could you solve this problem?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users