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

fix multi db connection problem #6

Merged
merged 1 commit into from Dec 14, 2017

Conversation

Projects
None yet
2 participants
@o0h
Contributor

o0h commented Dec 6, 2017

When same name table exits in multi database, table hashes conflicts and fixture will be broken.
So, with creating $tableHashes with $db->connection as prefix for this config, the problem will be solved.

now: $this->_tableHashes['users']`
will: $this->_tableHashes['test_another-users']

ex)

// In UsersFixture
class UsersFixture extends ChecksumTestFixture
{
    public $table = 'users';

    public $fields = [
        'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
         '_constraints' => [
            'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
        ],
    ];

    public $records = [
        [
            'id' => 1,
            'name' => 'foo'
        ]
    ];
}

// In AnotherUsersFixture
class AnotherUsersFixture extends ChecksumTestFixture
{
    public $table = 'users';

    public $connection = 'test_another';

    public $fields = [
        'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
         '_constraints' => [
            'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
        ],
    ];

    public $records = [
        [
            'id' => 1,
            'name' => 'bar'
        ]
    ];
}
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'.
file: /vendor/composer/cakephp/cakephp/src\/TestSuite\/Fixture\/FixtureManager.php
line: 347
@lorenzo

This comment has been minimized.

Member

lorenzo commented Dec 14, 2017

Thanks, this is very useful!

@lorenzo lorenzo merged commit 406c1ff into FriendsOfCake:master Dec 14, 2017

@o0h o0h deleted the o0h:fix-multi-database-connection branch Dec 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment