-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: php spark migrate on testing environment doesn't work #3309
Comments
This is confirmed. Tested on |
Did some digging and found the offending method in protected function getRequestObject()
{
if ($this->request instanceof Request)
{
return;
}
if (is_cli() && ENVIRONMENT !== 'testing')
{
// @codeCoverageIgnoreStart
$this->request = Services::clirequest($this->config);
// @codeCoverageIgnoreEnd
}
else
{
$this->request = Services::request($this->config);
// guess at protocol if needed
$this->request->setProtocolVersion($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1');
}
} Currently, on CLI if Maybe @lonnieezell , @MGatner or @michalsn can shed some light on this. |
I'm not entirely sure but my guess is that |
@MGatner I understand your point. But I need migrate into testing database to run unit test and integration test. How can I do that without |
Typically you would do this programmatically, either by specifying the migration namespaces on the Database Test Case (https://codeigniter4.github.io/CodeIgniter4/testing/database.html) or by using MigrationRunner directly in your fixture. I recommend checking out the CodeIgniter Playground if you are new to testing in the framework. It has some example test cases, tests, and docs (https://github.com/codeigniter4projects/playground/blob/develop/docs/testing.md) that should be helpful. |
Yes, biggest piece of advice here is don't use the environment "testing". That's the mode set when running phpunit and has special conditions built into the framework at various places to assist with that. For example, when running automated tests it's always running from the CLI and there are a number of times when you want to simulate an HTTP request so that check was placed there. I believe @MGatner gave the appropriate steps here so am closing it. If you still run into problems under environments other than |
Describe the bug
When I change environment variable CI_ENVIRONMENT to testing, the command
php spark migrate
doesn't work. I want to migrate all migrations files on app/Database/Migrations to test my app.It returns that there is an error on routes.
CodeIgniter 4 version
CodeIgniter CLI Tool - Version 4.0.3
Context
The text was updated successfully, but these errors were encountered: