Description
Description
This is a bit of a strange problem. I'll try to describe it and maybe wait for some instructions to provide more feedback (I realize that this is a partial report).
I'm writing the test for a command. This test necessarily needs the RunInSeparateProcess
attribute.
The test also uses the fetchTable()
method (it uses a table).
The table used by the test is obviously the same table that the command being tested also uses.
#[Test]
#[RunInSeparateProcess]
public function testExecute(): void
{
$MailBoxesTable = $this->fetchTable('MailBoxes');
// ...
$this->exec('fetch_mails -v');
// ...
}
What happens: the entire test method uses the default connection (and not the test one).
I tried playing with the various attributes PreserveGlobalState
, BackupStaticProperties
, BackupGlobals
, but with no changes.
What I think happens: I think that in the test fetchTable()
it loads the table with the real connection and this happens because RunInSeparateProcess
"breaks" something.
Then the test object code does the same thing, because it uses the already loaded table.
In fact, by doing this in the test:
$MailBoxesTable = $this->fetchTable('MailBoxes', ['connection' => ConnectionManager::get('test')]);
the problem is solved and both the test code and the test object code use the test connection.
I realize that in cases like this, using RunInSeparateProcess
can reliably lead to unpredictable outcomes and would be best avoided.
I'll try to ask anyway, also regarding where/what I can investigate. Thanks.
CakePHP Version
5.2
PHP Version
No response