cakephp-fixture-factories icon indicating copy to clipboard operation
cakephp-fixture-factories copied to clipboard

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

Open dreamingmind opened this issue 1 year ago • 1 comments

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 avatar Oct 24 '23 22:10 dreamingmind

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.

dreamingmind avatar Oct 25 '23 02:10 dreamingmind