You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MariaDB 10.4.18
What happened?
When I try to run unit tests on models declared in the App namespace, the models only reference the default database and not the test database.
And when I try to comment the default database, I get the following error:
CodeIgniter\Database\Exceptions\DatabaseException: Unable to connect to the database.
Main connection [MySQLi]: Access denied for user ''@'localhost' (using password: NO)
Same thing happens even when the environment is set as TESTING, i.e. CI_ENVIRONMENT = testing in the .env file.
Steps to Reproduce
Install Shield to a fresh CodeIgniter installation: composer require codeigniter4/shield. This is just to confirm that migrations run in the appropriate (test) database.
Create a model (eg. SampleModel.php) via command line: php spark make:model sample --suffix --table sample_table
Create a migration for the model: php spark make:migration create_sample_table and add fields for the up() method like so:
Running the command: php spark make:model modelname specifies the default group when the file is created, if it is not required, then I don't think it is needed.
PHP Version
8.2
CodeIgniter4 Version
4.4.2
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MariaDB 10.4.18
What happened?
When I try to run unit tests on models declared in the App namespace, the models only reference the default database and not the test database.
And when I try to comment the default database, I get the following error:
Same thing happens even when the environment is set as TESTING, i.e.
CI_ENVIRONMENT = testing
in the .env file.Steps to Reproduce
Install Shield to a fresh CodeIgniter installation:
composer require codeigniter4/shield
. This is just to confirm that migrations run in the appropriate (test) database.Create a model (eg. SampleModel.php) via command line:
php spark make:model sample --suffix --table sample_table
Create a migration for the model:
php spark make:migration create_sample_table
and add fields for theup()
method like so:Don't forget to drop the table in the
down()
method:$this->forge->dropTable('sample_table');
.env
file:vendor\bin\phpunit
Expected Output
I expected that the test would run without any error, as models in the App namespace are not supposed to be limited to the default database.
Anything else?
Commenting the
$DBGroup
property of the model class:// protected $DBGroup = 'default';`
seemed to resolve the issue, as pointed out by @datamweb which makes me to wonder why the 'default' table was hardcoded in the first place.
The text was updated successfully, but these errors were encountered: