Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index and databese id's dont match #35

Open
AdeAttwood opened this issue Mar 28, 2018 · 3 comments
Open

Index and databese id's dont match #35

AdeAttwood opened this issue Mar 28, 2018 · 3 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@AdeAttwood
Copy link

AdeAttwood commented Mar 28, 2018

Is anyone else having an issue with $index not being the same as the record id?
Because my database id's start at 1 and the index being passed into the faker template starts at 0 the record id does not match the index.

if in the loop was for ($i = 1; $i <= $this->count; $i++) { The index and the record id would be the same.

@cebe cebe added type:bug Bug status:to be verified Needs to be reproduced and validated. labels Apr 5, 2018
@cebe cebe added this to the 2.0.5 milestone Apr 5, 2018
@AdeAttwood
Copy link
Author

@cebe whats the plan now? Can I make the change or is it best to wait until the status is labelled "status:ready for adoption". Not sure on the workflow.

@cebe
Copy link
Member

cebe commented Apr 23, 2018

@AdeAttwood could you come up with a unit test that shows the problem?

@AdeAttwood
Copy link
Author

AdeAttwood commented Apr 23, 2018

@cube I have come up with this test. I did have an issue building the docker image, so I have run all the tests in a modified php:7.1-cli image. Dont know if the sqlite::memory dsn will work in your image thats a convo for another day.

    public function testIndexMatchesPrimaryKey()
    {
        $userTable = [
            'user_id' => 'pk',
            'username' => 'string',
            'email' => 'string',
            'auth_key' => 'string',
            'password' => 'string',
            'created_at' => 'integer',
            'updated_at' => 'integer'
        ];

        Yii::$app->db->createCommand()->createTable('user', $userTable)->execute();

        $this->_fixtureController->actionGenerate('user');
        $fixtureData = require Yii::getAlias('@runtime/faker/user.php');
        array_shift($userTable);

        Yii::$app->db->createCommand()->batchInsert('user', array_keys($userTable), $fixtureData)->execute();
        $rows = Yii::$app->db->createCommand('SELECT * FROM user')->queryAll();

        foreach ($rows as $row) {
            $validatePassword = Yii::$app->security->validatePassword('password_'.$row['user_id'], $row['password']);
            $this->assertTrue($validatePassword);
        }
    }

I had to add password to the user fixture from the docs. And also had to modify the moc app to include the database component.

    new $appClass(ArrayHelper::merge([
            'id' => 'testapp',
            'basePath' => __DIR__,
            'vendorPath' => dirname(__DIR__) . '/vendor',
            'components' => [
                'db' => [
                    'class' => '\yii\db\Connection',
                    'dsn' => 'sqlite::memory:',
                ],
            ],
        ], $config));

It did break one of the tests with Undefined index: profile0 because it will be profile1

@samdark samdark removed this from the 2.0.5 milestone Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants