Skip to content
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: can't run migrations when CI_ENVIRONMENT = testing #4033

Closed
kaleidoscopique opened this issue Dec 27, 2020 · 7 comments
Closed

Bug: can't run migrations when CI_ENVIRONMENT = testing #4033

kaleidoscopique opened this issue Dec 27, 2020 · 7 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@kaleidoscopique
Copy link
Contributor

Describe the bug
Impossible to run php spark migrate when CI_ENVIRONMENT = testing.

CodeIgniter 4 version
4.0.4 - stable

Affected module(s)
spark migrate and \App\Controllers\Cimigrate::index

Expected behavior, and steps to reproduce if appropriate

  • Install a fresh CI instance (with CI_ENVIRONMENT = development)
  • Create some DB migrations files (or even just php spark session:migration)
  • Deploy with CI_ENVIRONMENT = testing in dotenv file.
  • Try to execute migrations : php spark migrate and this error happens:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-12-27 13:38:10pm
ERROR: 404
Controller or its method is not found: \App\Controllers\Cimigrate::index

And it works like a charm when you replace CI_ENVIRONMENT = testing to CI_ENVIRONMENT = development.

This guy had the same issue in February 2020 : https://forum.codeigniter.com/thread-75608.html

Context

  • OS: Ubuntu Server 20.04
  • Web server : Nginx
  • PHP version : 7.4.13 (cli) (built: Dec 11 2020 08:31:11) / (specifically a dockerized PHP FastCGI in my case).
@kaleidoscopique kaleidoscopique added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 27, 2020
@iRedds
Copy link
Collaborator

iRedds commented Dec 27, 2020

Run php spark migrate. Then switch your environment to testing.
It's not a bug. This is strange CI magic

if (is_cli() && ! (ENVIRONMENT === 'testing'))
{
    $this->request = Services::clirequest($this->config);
}
else
{
    $this->request = Services::request($this->config);
    // guess at protocol if needed
    $this->request->setProtocolVersion($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1');
}

@kenjis
Copy link
Member

kenjis commented Dec 27, 2020

I have confirmed the behavior.

dotenv: CI_ENVIRONMENT = development

$ php spark migrate

CodeIgniter v4.0.4 Command Line Tool - Server Time: 2020-12-28 08:07:47 UTC+09:00

An uncaught Exception was encountered

Type:        Error
Message:     Call to undefined method CodeIgniter\HTTP\IncomingRequest::getSegments()
Filename:    /Users/kenji/work/codeigniter/ci4-news/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php
Line Number: 929

	Backtrace:
						-427 - /Users/kenji/work/codeigniter/ci4-news/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php::runController
								-333 - /Users/kenji/work/codeigniter/ci4-news/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php::handleRequest
								-61 - /Users/kenji/work/codeigniter/ci4-news/vendor/codeigniter4/codeigniter4/system/CLI/Console.php::run
								-57 - /Users/kenji/work/codeigniter/ci4-news/spark::run

dotenv: CI_ENVIRONMENT = testing

$ php spark migrate

CodeIgniter v4.0.4 Command Line Tool - Server Time: 2020-12-28 08:08:11 UTC+09:00

すべての新しいマイグレーションを実行しています...
	実行中: (App) 2020-12-27-230706_App\Database\Migrations\MigrationCreateCiSessionsTable
Done migrations.

@kenjis
Copy link
Member

kenjis commented Dec 27, 2020

@iRedds How can we create table ci_sessions in test database with spark migrate?

@iRedds
Copy link
Collaborator

iRedds commented Dec 28, 2020

@kenjis, are you getting an error when CI_ENVIRONMENT = development?
A backtrace in the error text indicates that the code is being executed in the dev branch. The master branch does not match the lines.

@iRedds How can we create table ci_sessions in test database with spark migrate?

The easiest way is to set the test database in database.default before migrating. =)

@kenjis
Copy link
Member

kenjis commented Dec 28, 2020

@iRedds Yes, I use the dev branch.

The easiest way is to set the test database in database.default before migrating. =)

Very tricky. I can't bear!

@paulbalandan
Copy link
Member

@kaleidoscopique please see #3309 for the explanation.

You do not set the testing environment manually. This is set automatically by PHPUnit during unit tests. If you need to test something, it might be better to test them under the development environment.

@paulbalandan
Copy link
Member

@kenjis a little side note. it seems you are using the dev branch but your debig backtrace is not yet updated. Since v4.0.4 there are many additions/ changes to app/, public/, spark, and env. You should update them too.

Shameless plug: You can try this library of mine to do the update automatically. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

4 participants