cakephp-fixture-factories
cakephp-fixture-factories copied to clipboard
Factories use the wrong connection when called from a PHPUnit v10.x static data providers
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?
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.