I'm using RedBean and PHPUnit for my unit testing.
In the setup for each test class, I've got:
R::setup( 'sqlite::memory:');
Some classes also use another database, so I use:
R::addDatabase( 'active', ...)
In the teardown, I've got:
R::close();
I'm getting an error when running all tests at the setup line stating:
RedBeanPHP\RedException: A database has already be specified for this key.
This leads me to two questions (sorry if I'm missing something obvious):
1. Is there another way that I should/can close the database connection so that I can create a new default one? The code shows that R::close closes the DB adaptor but it doesn't seem to touch the toolboxes array.
2. Is there an easy way to check to see if the default toolbox has already been created?
I was able to get around it with the following but was assuming something else might be cleaner:
try {
R::setup( 'sqlite::memory:' );
}
catch ( RedBeanPHP\RedException $e ) {
R::nuke();
}
Thanks.