Level 17
Looks good to me. Well done getting started in testing! :-)
2 likes
Hi there,
This is my first test, so be easy on me.
Please give me your thoughts.
class SearchEmployeeByIdTest extends TestCase
{
use DatabaseTransactions;
/**
* Search an employee by the given id
* @test
* @return void
*/
public function it_finds_an_employee_by_id()
{
$employee_id = '00007F65E9';
$employeeName = 'John';
$company = factory(Company::class)->create();
$plant = factory(Plant::class)->create();
$company->plants()->save($plant);
$employees = factory(Employee::class, 4)->create();
$plant->employees()->saveMany([
$employees[0],
$employees[1],
$employees[2],
$employees[3]
]);
$employeeWithId = factory(Employee::class)->create([
'name' => $employeeName,
'employee_id' => $employee_id
]);
$plant->employees()->save($employeeWithId);
$this->assertEquals($employee, $employeeWithId->employee_id);
$this->assertCount(4, $employees);
$this->actingAs($plant)
->withSession([
'author_id' => $plant->id,
'company_id' => $company->id
])
->visit('/employee/search?employee_id=' . $employee_id)
->see($employeeName);
}
}
Thank you!
Please or to participate in this conversation.