My test:
class FloorStackTest extends TestCase
{
use RefreshDatabase, WithFaker, DatabaseMigrations;
protected $endPoint = '/endpoint';
public function test_unit_type_note_added_successfully()
{
$this->signIn();
$this->withoutExceptionHandling();
$unitType = UnitType::factory()->create();
$note = $this->faker()->sentence(3);
$resp = $this->ajaxPost($this->admin_route.$this->endPoint."/".$unitType->property_version_id."/save-ut-note",[
'notes' => [
[
"ut_note_id" => "utn_".$unitType->id,
"note" => $note
]
]
])->assertStatus(Response::HTTP_OK);
$results = [
'notes' => $note
];
//i could print upto here
dd('hit');
$this->assertDatabaseHas(UnitType::class,$results);
//but could not print here
dd('hit');
}
}
I am using sqlite
for testing and I am using laravel 8 (which was previously updated from laravel 5, just in case to confirm)
I the above code, you can see the point upto where I could print hit
.
I am using .env.testing
DB_CONNECTION=sqlite
DB_DATABASE="database/test.sqlite"
DB_FOREIGN_KEYS=false
I have already been using: use RefreshDatabase
but still it is showing error. and the full error is:
Tests\Feature\FloorStackTest::test_unit_type_note_added_successfully
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: App\Models\UnitType (SQL: select count(*) as aggregate from "App\Models\UnitType" where ("notes" = Eveniet incidunt consequuntur dolore est.))
And my model UnitType
has this
use SoftDeletes, HasFactory;
protected $table = 'unit_types';
protected $guarded = ['id'];
protected $dates = ['created_at','updated_at','deleted_at'];