PestPHP and Integration Test
I have a project in Laravel 8, and I want to perform integration tests on the system. To do this, I need preloaded information in the database, such as the client, the payment they are making, etc. What is the correct way to add this information to the database so that when I call the endpoint or service, everything works as it should?
I have made some attempts, but they feel very lacking.
Here is an example:
it('test01', function() {
GlobalHelper::logContextProcessId();
$this->seed(ReprocesoTestSeeder::class);
$reproceso = new Reproceso(14016);
$reproceso->iniciar();
// asserts here
});
And here is the content of ReprocesoTestSeeder:
class ReprocesoTestSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model1::truncate();
Model2::truncate();
Model3::truncate();
Model1::factory()->create(['Model1 data']);
Model2::factory()->create(['Model2 data']);
}
}
I need to test that the process is performing the calculations correctly. To validate this, I need a controlled data input ( in 7 different database tables ) so I can verify that the calculations produce the expected results. However, I don’t feel like I’m inserting all this data in the correct way.
Could someone with experience guide me on the proper way to perform this type of testing?
Thank you.
Please or to participate in this conversation.