Answer the question
In order to leave comments, you need to log in
How to set up a database when testing with codeception?
I want to make a test for a method that checks if the user has this login when registering.
Method Code
public function ifExistUsername(string $username)
{
$user = User::where('username', $username)->first();
if ($user)
return 'Пользователь с таким логином уже есть.';
return;
}
public function testIfExistUsername()
{
$validator = new FormValidator();
$username = 'user0';
$this->assertContains($validator->ifExistUsername($username), 'Пользователь с таким логином уже есть.');
}
- Db:
dsn: 'mysql:host=localhost;dbname=testdb'
user: 'root'
password: ''
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
Answer the question
In order to leave comments, you need to log in
The Db module settings for codeception will not be used by the system you are testing. They are needed in order to upload the dump to an empty database, clean the database after each test and delete everything after the tests are completed. Your system should have its own mechanisms for selecting database settings for the testing process.
The most true way is probably to write a module for codeception, as is done for all major frameworks, incl. Laravel https://github.com/Codeception/Codeception/blob/2.... https://github.com/Codeception/Codeception/blob/2....
Well, if you use dot-env configuration - be careful. Codeception can load settings from all .env files lying next to codeception.yml in a chaotic manner, and this is very sluggishly written in the docks, so even .env.example can fundamentally break your tests)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question