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

Factories use the wrong connection when called from a PHPUnit v10.x static data providers #233

Open
dreamingmind opened this issue Oct 24, 2023 · 1 comment

Comments

@dreamingmind
Copy link
Contributor

dreamingmind commented Oct 24, 2023

When I use a Factory to prepare some fixture data in a static data provider, the records are created in the default database rather than the testing database

This is the kind of thing I'm doing:

    /**
     * @dataProvider normalizeArgVariants
     * @param $input
     * @param $expected
     * @return void
     */
    public function test_someMethod($input, $expected)
    {
        //test logic;
    }

    public static function normalizeArgVariants(): array
    {
        $oldNode = NodeFactory::make(1)->persist();

        return [
            [$oldNode, $oldNode->id],
            [12, 12],
            ['122', 122],
    }

I'm struggling a little with this change to static data providers in general, so perhaps this is the wrong approach?

@dreamingmind
Copy link
Contributor Author

This seems to be related to #187 .

Aliasing the connection as jamisonbryant suggested in his March 16 update to his issue helped, but didn't completely solve my issue.

Making the changes in bootstrap got me past a 1062 Duplicate entry '1741177057' for key error but records are still being written to the wrong db. That result is actually more confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant