I think one of your migrations is incorrect. Can you show us the migration with the project_id column in it?
Phpunit configuration refresh my database
When I run phpunit --stop-on-failure command I got an error:
Tests\Unit\ExampleTest::testBasicTest
Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'project_id' doesn't exist in table (SQL: alter table `tasks` add constraint `tasks_project_id_foreign` foreign key (`project_id`) references `projects` (`id`) on delete cascade)
After that I noticed my database is missing most of the tables, so it looks like test makes database migration reset.
i cannot find the reason of that because:
- My configuration points to doing tests in memory
- Im running only default Laravel test
Here is my configuration:
phpunit.xml
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite_testing"/>
config\database.php
'connections' => [
//...
'sqlite_testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
],
default unit test - tests\Unit\ExampleTest.php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
use DatabaseMigrations;
public function testBasicTest()
{
$this->assertTrue(true);
}
}
Commenting out line use DatabaseMigrations; makes that database is not resetting, but it doesn`t solve the problem. Database for testing should be separate.
What am I missing?
@wizjo I believe that you won't be able to run any tests with an in-memory database until you are sure that running php artisan migrate on an empty database corresponds with your current database.
Well, at least you now know what the issue is, and consider not skipping migrations in future, even when you are working alone on a project.
I hope you manage to fix your migrations. :)
Please or to participate in this conversation.